I want to use node_modules js in Magento2 but there is a require js conflict error. How can I solved and use node_modules in magento2?


requirejs-config.js code:

var config = { 
    map: { 
        '*': { 

// This light wallet is using node_modules packages and due to that mismatch error has appeared.

  • Can you please share the conflict error here? – Sumit Aug 30 '19 at 6:44
  • Error: Mismatched anonymous define() module: function($) {}); I get this error due to not use define() in js. but the I use lightwallet.js and that js require node_modules js and those js are creating a confliction. – Adilkadiyawala Aug 30 '19 at 7:09
  • OK, please update your question with requirejs-config.js file. So I cab debug it further. – Sumit Aug 30 '19 at 7:25
  • @Sumit, This is my requirejs-config.js code: var config = { map: { '*': { lightwallet: 'Unitedcrowd_Tokensale/js/lightwallet' } } }; This lightwallet js is used to node_module js. – Adilkadiyawala Sep 5 '19 at 5:17

Alright, You are able to get node_modules Javascript assets to be available via RequireJS. Using Bootstrap as an example, this is what I did inside my theme folder:

  1. Required bootstrap in package.json and installed with yarn
  2. Created a symbolic link: web/node_modules pointing to ../node_modules
  3. Created a requirejs-config.js file in your theme

enter image description here

The only downside What I feel is that setup:static-content:deploy takes a bit longer and attempts to compile the .less files in the packages.

I hope this will help

  • Thanks for your reply.. earlier I saw the same post but my problem is I need to use another modules like web3, web3-eth etc. So problem is those js package require lots of all other js from node_modules. So I think it's impossible to create a symbolic link for all of those js – Adilkadiyawala Aug 30 '19 at 6:21

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.