require(‘constants’) in webpack@2 requires nodejs native constants

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


What is the current behavior?

  1. Setup in webpack.config.js module.resolver: [ path.resolve(__dirname, 'src'), 'node_modules' ].
  2. Create file src/constants/index.js with content, e.g. module.exports = { SOME_CONST: SOME_CONST' };
  3. Require this file as require('constants').
  4. Get nodejs constants object contains EEXIST and SIGTERM.

The same with import.

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

You may clone webpack-require-constants and do following:

  1. cd webpack2
  2. npm install
  3. npm run build
  4. Open public/index.html file.

What is the expected behavior?

I’m not really sure is it a bug in webpack2 or webpack1. Webpack1 requires src/constants. You can see it in the same repo in directory webpack1.

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

  • nodejs v7.1.0
  • webpack@2.3.3 — requires nodejs constants
  • webpack@1.14.0 — requires src/constants
  • mac os 10.10.5

Author: Fantashit

1 thought on “require(‘constants’) in webpack@2 requires nodejs native constants

Comments are closed.