-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Only honor relative NODE_PATH #1194
Conversation
I am sorry but I am still experiencing trouble getting a successful build. I went through this thread but could not locate how to fix this. Problem: Whenever I use ES6 feature like template string or fat arrow function notation, as helper JS functions to fetch data and pass it to React components, npm start works fine but npm run build fails. NODE_PATH is not set to anything. Any pointers would greatly help.
Thanks! |
Looks like you're trying to import a JavaScript file from outside src/; this is not supported. The file will not be compiled. This behavior will most likely be disallowed in 0.10. |
Oh wow! Thanks for catching that. I moved that folder to src and it compiles successfully! |
We used to honor
NODE_PATH
because it provides a relatively convenient way to allow absolute imports for people who need them:NODE_PATH=src npm start
.However this backfired with #1023 and #815.
The best analysis is in #1023 (comment).
Sometimes, a module (which may be inside a dependency) may depend on Node core modules like
events
. In this case Webpack attempts to shim it with node-libs-browser. However it only attempts to shim it if it can't resolve the module name using the regular mechanism. The problem is that some Linux distributions include Node sources intoNODE_PATH
. Therefore, since we honorNODE_PATH
, Webpack findsevents
in Node.js sources on those systems, and thus doesn't attempt to shim it. As a result you get the latest version from Node.js itself which is likely incompatible with the browsers.To fix this, we need a way to not allow Node.js core modules to resolve to Node.js sources even if they exist in
NODE_PATH
. I don't see any easy way to do this. However we can sidestep the issue by not respecting absolute paths inNODE_PATH
. The only reason we addedNODE_PATH
support is for absolute imports (NODE_PATH=src npm start
), whereNODE_PATH
itself is relative. Any other uses of it are inherently dangerous (and won't work across systems anyway). So I think it should be safe to just stop honoring absoluteNODE_PATH
altogether, thus solving both issues.It is technically a breaking change but for a use case we never intended to support. I have a hard time believing anyone could've intentionally relied on this, and if it breaks anyone, it will more likely uncover a bug. Therefore I think this is safe to go in 0.8.x, especially given that it fixes more egregious bugs that have been affecting people for months, and 0.8 has been out for just four days.