0

I am having some trouble getting process.env.NODE_ENV set in webpack production build.

I am setting this via

new webpack.DefinePlugin({
     'process.env': {
       NODE_ENV: JSON.stringify('production'),
     },
 }),

In my app code this is working fine I have:

console.log(process.env.NODE_ENV);

which gets converted to

console.log("production");

in the compiled output from the build.

However I am getting errors from redux that this has not been set.

in the output I have this code

if (process.env.NODE_ENV !== 'production' && typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
          (0, _warning2['default'])('You are currently using minified code outside of NODE_ENV === \'production\'. ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' + 'to ensure you have the correct code for your production build.');
        }

and process.env is an empty object. So it looks as though webpack is not injecting this correctly. The function that contains the redux check starts like this:

    /* 152 */
    /***/ function(module, exports, __webpack_require__) {

        /* WEBPACK VAR INJECTION */(function(process) {

I'm not sure what I'm missing here but looks like I'm not getting the optimised build version of redux and maybe some other dependencies inn my build because of this error.

I am usually splitting vendor code and app code into separate files during production build and uglifing but I have run this test outputting to a single file and without the minification just to test this issue

jamie holliday
  • 1,617
  • 9
  • 26
  • 39

0 Answers0