Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loaders configured to accept files in node_modules may override alias setting, including libraries multiple times #2441

Closed
seansfkelley opened this issue May 6, 2016 · 4 comments
Labels

Comments

@seansfkelley
Copy link

The repro for this bug is a little involved, so I made a repo for it: https://github.com/seansfkelley/node-modules-alias-loader-bug

Summary: if you want to do local development across multiple repos with npm link and have a singleton specified in the alias config block, this singleton can still be accidentally included multiple times if you have a loader configured to accept files from node_modules/.

Real-world example: I'm developing two React components from separate repos at the same time (say, cause one is consumed by the other). Each one was set up (i.e., npm installed) independently, but now they've been linked with npm link. React has to be a singleton on the page, otherwise it throws errors, but I have two copies of React in my module tree. To get around this, I specify an alias for React pointing to the parent module's instance. I also want to get source maps from the child project, so I bring in source-map-loader and explicitly configure it to look for source maps in node_modules/, as it is intended to do. Running Webpack will now include multiple instances of React.

@sokra
Copy link
Member

sokra commented May 6, 2016

I know. This issue was reported multiple times before. That's how npm and node.js resolving works. webpack is aligned with the node resolving algorithm.

As workaround you can use the alias option as you mentioned.

@seansfkelley
Copy link
Author

I think you misunderstood the original bug report. The alias option doesn't work in this specific scenario. The normal node resolution algorithm would pull in two distinct copies in this case, but the combination of alias and a loader configured for node_modules actually pulls in the same copy two times -- so it's actually doing some weird, unexpected hybrid of what you would expect from the module-resolution algorithm clashing with the alias configuration.

@sokra
Copy link
Member

sokra commented May 6, 2016

That's related to the other issue you reported. As workaround alias the source-map-loader too (resolveLoader.alias) or use an absolute path to the loader in the loader configuration.

@seansfkelley
Copy link
Author

Oh, that's very strange and not very obvious, but it works in my test repo so I'll close this out. Thank you! So it seems that each instance of a loader ends up with its own copies of the modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants