1

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.

Sumit
5,0482 gold badges22 silver badges36 bronze badges
asked Aug 16, 2019 at 20:40
1
  • 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 redeploy Commented Aug 19, 2019 at 10:40

2 Answers 2

0

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']
};
answered Aug 17, 2019 at 15:48
1
  • That did it. I haven't seen this in any of the tutorials. Will look into it more, thanks. Commented Aug 19, 2019 at 14:16
0

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.

answered Aug 16, 2019 at 20:49
5
  • Did that, but it still doesn't work. Commented Aug 16, 2019 at 20:59
  • Did you flush the cache after also have u checked your js has been deployed into pub/static Commented Aug 16, 2019 at 21:09
  • I have done that, but I don't see the js in the pub/static Commented Aug 16, 2019 at 21:10
  • and you have placed your JS in app/code/NewShop/HelloWorld/view/frontend/web/js correct Commented Aug 16, 2019 at 21:22
  • Yeah it's in that folder. Commented Aug 16, 2019 at 21:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.