Resolve NODE_PATH by default

Do you want to request a feature or report a bug?

Request a feature.

What is the current behavior?

If the current behavior is a bug, please provide the steps to reproduce.

Paths defined in the NODE_PATH environment variable are ignored unless manually added in the webpack config under resolve.modules.

I made a quick demo with 3 scripts in the package.json. All of these scripts will have to parse a require('lib/foo') statement.

npm run compile:browserify:
npm run compile:webpack: errors out, unable to resolve 'lib/foo'
npm test:

What is the expected behavior?

By default, webpack should resolve node_modules as well as directories in NODE_PATH.

If this is a feature request, what is motivation or use case for changing the behavior?

  • Node supports this (1, 2)
  • Other major libraries like browserify and mocha resolve NODE_PATH by default (see demo repo)

This feature was also added to create-react-app (see discussion, implementation) pretty recently. However, that solution only passes NODE_PATH to the generated webpack config. I’d like this to be webpack’s default behaviour 🙂

I’ve seen a few issues where adding NODE_PATH to resolve.root (webpack v1) was suggested as a solution, but haven’t come across any discussion about whether this should be supported by default. Apologies if I’ve missed it, I’d be keen to know if this has been considered before!

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

Node v7.4.0
Webpack v2.2.1
macOS Sierra 10.12.3

Author: Fantashit

1 thought on “Resolve NODE_PATH by default

Comments are closed.