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.

  • 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 – Dava Gordon Aug 19 at 10:40
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']
};
  • That did it. I haven't seen this in any of the tutorials. Will look into it more, thanks. – Kibret Aug 19 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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.