0

I am using webpack to build my app and I use a library (eventemitter4) that itself depends on another library (underscore).

However, I am already using in my application an alternative to underscore (lodash and more exactly the es6 version). I would like eventemitter4 to use this later library and avoid including in my build the two.

I install my dependencies using npm install. As a result, underscore is bundled as a subdirectory inside the eventemitter4's directory.

It tried to set aliases but I could not make it work:

alias: {
  "underscore": "lodash-es",
  "lodash": "lodash-es",
  "~/underscore": "lodash-es"
}

raises

ERROR in ./~/eventemitter4/index.js
Module not found: Error: Cannot resolve module 'lodash-es' in /Users/me/myapp/node_modules/eventemitter4
@ ./~/eventemitter4/index.js 6:2-23

If I do not add "~/underscore": "lodash-es", the sub-underscore is included instead of lodash.

Any idea?

Thank you very much for your help.

1 Answer 1

1

I actually found the reason. The alias was working. The cause of the error was that lodash-es does not provide a main attribute in his package.json (it only provides an esnext:main which is not recognised by webpack).

I solve the issue by using:

alias: {
  "underscore": "lodash-es",
  "lodash": "lodash-es/lodash",
  "~/underscore": "lodash-es"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.