I am building a module, and the HTML loads fine, but the JS isn't. Here is what I have:
- Vendor Name: NewShop
- Module Name: HelloWorld
File: app/code/NewShop/HelloWorld/view/frontend/requirejs-config.js
var config = {
map: {
'*': {
"helloworld": "NewShop_HelloWorld/js/newshop_helloworld",
}
}
};
File: app/code/NewShop/HelloWorld/view/frontend/web/js/newshop_helloworld.js
require(["helloworld"], function($) {
console.log('Hello World!')
});
I cleared up the cache and everything. I can't see the console message show up, even though the module shows fine.
-
firstly remove the $ as you have not included jquery so $ is not a valid parameter secondly add the ; at the end of the console.log finally delete all content in var/view_preprocessed and pub static and redeployDava Gordon– Dava Gordon2019年08月19日 10:40:22 +00:00Commented Aug 19, 2019 at 10:40
2 Answers 2
We will need to inject the RequireJs module into the page, can you try the deps configuration below:
var config = {
map: {
'*': {
"helloworld": "NewShop_HelloWorld/js/newshop_helloworld",
}
},
deps: ['NewShop_HelloWorld/js/newshop_helloworld']
};
-
That did it. I haven't seen this in any of the tutorials. Will look into it more, thanks.Kibret– Kibret2019年08月19日 14:16:35 +00:00Commented Aug 19, 2019 at 14:16
If you have added the JS to the your require JS you will need to redeploy your static content. id suggests removing the preprocessed data first
rm -rf var/view_preprocessed/*
Once you have done this you just need to run the deployment again
bin/magento setup:static-content:deloy
Remember to add your additional languages if you have any.
-
Did that, but it still doesn't work.Kibret– Kibret2019年08月16日 20:59:42 +00:00Commented Aug 16, 2019 at 20:59
-
Did you flush the cache after also have u checked your js has been deployed into pub/staticDava Gordon– Dava Gordon2019年08月16日 21:09:25 +00:00Commented Aug 16, 2019 at 21:09
-
I have done that, but I don't see the js in the pub/staticKibret– Kibret2019年08月16日 21:10:25 +00:00Commented Aug 16, 2019 at 21:10
-
and you have placed your JS in app/code/NewShop/HelloWorld/view/frontend/web/js correctDava Gordon– Dava Gordon2019年08月16日 21:22:04 +00:00Commented Aug 16, 2019 at 21:22
-
Yeah it's in that folder.Kibret– Kibret2019年08月16日 21:23:35 +00:00Commented Aug 16, 2019 at 21:23
Explore related questions
See similar questions with these tags.