[英]It looks like you're using a minified copy of the development build of React
I am using this software: 我正在使用此软件:
All the stuff configured (most of) as in https://github.com/davezuko/react-redux-starter-kit 配置的所有东西(大部分)在https://github.com/davezuko/react-redux-starter-kit中
I've already developed multiple projects with the same starter kit, and never had this problem. 我已经使用相同的入门工具包开发了多个项目,但从未遇到过这个问题。
I launch compilation with the following command: 我使用以下命令启动编译:
$ NODE_ENV=production npm run compile
ENV var is set correctly, I can see as compiler output: ENV var设置正确,我可以看到编译器输出:
app:config:project Creating default configuration. +0ms
app:config:project Looking for environment overrides for NODE_ENV "production". +4ms
app:config:project Found overrides, applying to default configuration. +2ms
app:config:webpack Creating configuration. +0ms
app:config:webpack DefinePlugin { 'process.env': { NODE_ENV: '"production"' },
'$LOCALES': '{"en-US":"en","it-IT":"ita"}',
NODE_ENV: 'production',
__DEV__: false,
__PROD__: true,
__STAGING__: false,
__TEST__: false,
__COVERAGE__: false,
__BASENAME__: '""' } +1ms
app:config:webpack Enabling plugins for production (OccurenceOrder, Dedupe & UglifyJS). +14ms
app:config:webpack Applying ExtractTextPlugin to CSS loaders. +111ms
app:bin:compile Starting compiler. +1ms
I know that I've to inject process.env.NODE_ENV
inside compiled code, because in a browser env is not usable. 我知道我必须将
process.env.NODE_ENV
注入已编译的代码中,因为在浏览器中env不可用。
I know this is done in webpack with the following (extract from my webpack.config) 我知道这是在webpack中完成以下操作(从我的webpack.config中提取)
webpackConfig.plugins = [
new webpack.DefinePlugin(project.globals),
...
]
where projects.globals
is the same as appear in the compiler output above: 其中
projects.globals
与上面的编译器输出中显示的相同:
config.globals = {
'process.env' : {
'NODE_ENV' : JSON.stringify(config.env)
},
'$LOCALES' : JSON.stringify(config.i18n.locales),
'NODE_ENV' : config.env,
'__DEV__' : config.env === 'development',
'__PROD__' : config.env === 'production',
'__STAGING__' : config.env === 'staging',
'__TEST__' : config.env === 'test',
'__COVERAGE__' : !argv.watch && config.env === 'test',
'__BASENAME__' : JSON.stringify(process.env.BASENAME || '')
}
and config.env
is defined also: 和
config.env
也定义:
const config = {
env : process.env.NODE_ENV || 'development',
...
Without running the UglifyJsPlugin I can see in the output many 如果不运行UglifyJsPlugin,我会在输出中看到很多
if (false):
// some check like "production" !== process.env.NODE_ENV
and it seems correct, because I read in some github issue ( https://github.com/webpack/webpack/issues/868 ) that the if (false)
is generated by webpack because it injects correctly the process.env.NODE_ENV
value, since the original code should look something like 似乎是正确的,因为我读过一些github问题( https://github.com/webpack/webpack/issues/868),if(false
if (false)
是由webpack生成的,因为它正确注入了process.env.NODE_ENV
值,因为原始程式码应该看起来像
if (!"production" === process.env.NODE_ENV) {
...
if("production" === process.env.NODE_ENV)
}
Ok, now I enable the UglifyJsPlugin: 好的,现在我启用UglifyJsPlugin:
} else if (__PROD__ || __STAGING__) {
debug('Enabling plugins for production (OccurenceOrder, Dedupe & UglifyJS).')
webpackConfig.plugins.push(
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress : {
unused : true,
dead_code : true,
warnings : false
}
}),
new webpack.optimize.AggressiveMergingPlugin()
)
}
And the output is full of 并且输出充满了
"production"!==t.env.NODE_ENV
and the warning appears in the console: 并且警告出现在控制台中:
Warning: It looks like you're using a minified copy of the development build of React. When deploying React apps to production, make sure to use the production build which skips development warnings and is faster. See https://fb[dot]me/react-minification for more details.
I've tried all the methods suggested in the first 2/3 google results pages searching for such error and "webpack process.env.NODE_ENV" but with no luck. 我尝试了前2/3个google结果页中建议的所有方法,以搜索此类错误和“ webpack process.env.NODE_ENV”,但没有成功。
(Posted solution on behalf of the question author) . (代表问题作者发布解决方案) 。
The problem was with a third party library which itself included a not minified version of React. 问题出在第三方库本身包含未缩小版本的React中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.