I'm getting this error message on a React/Redux app that is minified and packaged with Browserify and Gulp and deployed to Heroku.
bundle.js:39 You are currently using minified code outside of NODE_ENV === 'production'. This means that you are running a slower development build of Redux.
But it seems the build step is being done in NODE_ENV = 'production'
.
I've a task that set the env variables like so
gulp.task('apply-prod-environment', function() {
return process.env.NODE_ENV = 'production';
});
And the logs on Heroku show the ENV is production:
To guarantee the apply-prod-environment
runs before the other tasks, I'm using RunSequence
Gulp plugin.
gulp.task('buildProd', cb => {
runSequence(
'apply-prod-environment',
'task-1',
'task-2',
'etc',
cb
);
});
EDIT
Second Try..
import envify from 'envify/custom';
function buildJS(sourceFile, {setEnv}) {
return browserify(sourceFile)
.transform(babelify, {
presets: ['es2015', 'react', 'stage-2']
})
.transform(envify({
NODE_ENV: setEnv
}))
.bundle()
.on('error', (e) => {
gutil.log(e);
});
}
Still Getting same Error
Third Try..
function buildJS(sourceFile, {setEnv}) {
return browserify(sourceFile)
.transform(babelify, {
presets: ['es2015', 'react', 'stage-2']
})
.transform(
{global: true},
envify({
NODE_ENV: setEnv
})
)
.bundle()
.on('error', (e) => {
gutil.log(e);
});
}
Still Getting same Error
I struggled with this same problem and I ended up using loose-envify to mock the environment variables that I wanted to override.
Then, my gulp task looked like this: