简体   繁体   English

看起来您正在使用React开发版本的缩小版本

[英]It looks like you're using a minified copy of the development build of React

I am using this software: 我正在使用此软件:

  • Webpack 1.15.0 Webpack 1.15.0
  • React 15.5.4 反应15.5.4

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.

相关问题 reactjs的生产Webpack版本-看起来您正在使用React开发版本的缩小版本 - Production webpack build of reactjs - It looks like you're using a minified copy of the development build of React 看起来您正在使用 Firebase JS SDK in React App &amp; Invalid API 密钥的开发版本 - It looks like you're using the development build of the Firebase JS SDK in React App & Invalid API key 看起来您正在使用 Firebase JS SDK 的开发版本。 将 Firebase 应用部署到生产环境时, - It looks like you're using the development build of the Firebase JS SDK. When deploying Firebase apps to production, 如何停止警告:看起来你正在使用Firebase JS SDK的开发版本? - How to stop the warning: It looks like you're using the development build of the Firebase JS SDK? 看起来您正在为屏幕“添加”的“组件”道具传递内联 function(例如 component={() =><somecomponent /> }) - Looks like you're passing an inline function for 'component' prop for the screen 'Add' (e.g. component={() => <SomeComponent />}) 即使是开发模式,React 也会出现 Minified React 错误 - React saids Minified React error even it is development mode webpack production build 总是返回 这个页面使用的是 React 的开发 build - Webpack production build always returns This page is using the development build of React 缩小反应错误 #301 | 无限循环| 重新渲染 - Minified react error #301 | Infinity-Loop | Re_rendering 无法将 typescript 与 expo 一起使用 - “看起来您正在尝试使用 TypeScript,但没有安装所需的依赖项” - Unable to use typescript with expo - "It looks like you're trying to use TypeScript but don't have the required dependencies installed" React build 看起来与 React dev 不同 - React build looks different than React dev
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM