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:
gulp.task('javascript:prod', function() {
return browserify("app/main.js", { debug: !IS_PROD })
.transform("babelify", { presets: [ "es2015", "react" ], plugins: [ "transform-object-rest-spread", "transform-function-bind", "transform-object-assign" ] })
.transform('loose-envify', { NODE_ENV: 'production' })
.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest("./public/javascripts/"))
.pipe(rev.manifest({merge:true, base: 'build/assets'}))
.pipe(gulp.dest('build/assets'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With