For some reason, my js component isn't getting created when the static-content is deployed. I get a console error saying [ERROR] Failed to load the "Magento_Customer/js/previousShopper" component. as well as another error saying that the js file isn't found.
When I look in pub/static/frontend, I don't see it there, which obviously means it's not being generated, even after I used setup:static-content:deploy -f
Any idea why it's not generating? know that the html is talking to the js, because the 'callSomething' in the js file changed from gray to yellow in phpstorm
thanks
I've copied the register.phtml form to app/design/frontend//<child_theme>/Magento_Customer/templates/form/register.phtml. I added a div with this
<div id="shopped-with-sf" data-bind="scope: 'previousShopper'"> <!-- ko template: getTemplate() --><!-- /ko --> </div>
and at the bottom, I added this
<script type="text/x-magento-init"> { "#shopped-with-sf": { "Magento_Ui/js/core/app": { "components": { "previousShopper": { "component": "Magento_Customer/js/previousShopper", "template": "Magento_Customer/previousShopper" } } } } } </script>
then, under my Magento_Customer/web/js/view/previousShopper.js
define(['jquery', 'uiComponent'], function ($, Component) { 'use strict' return Component.extend({ defaults: { shoppingType: '', yesButton: '.yes-button', noButton: '.no-button' }, initObservable: function () { this._super().observe(['shoppingType']); return this; }, callSomething: function () { console.log('were calling'); } }) })
and in Magento_Customer/web/template/previousShopper.html
<h1>this is on the html template page</h1> <button data-bind="click: callSomething">button</button>
Solved! Go to Solution.
Hi @web_master12,
Js file path is wrong. Please correct that
Magento_Customer/web/js/view/previousShopper.js
Change to
Magento_Customer/web/js/previousShopper.js
Deploy the content after that.
Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!
Hi @web_master12,
Js file path is wrong. Please correct that
Magento_Customer/web/js/view/previousShopper.js
Change to
Magento_Customer/web/js/previousShopper.js
Deploy the content after that.
Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!
Thanks. After playing around with things, I found that I had put my js file into web/js/view/previousShopper.js. Changing the component path to add /view fixed it for me