ReactDOM RSS renderToString生产错误

时间:2018-03-07 14:57:49

标签: reactjs webpack react-hot-loader ssr

我为react16创建了新的样板。

https://github.com/jasonvillalon/react16-boilerplate

使用以下方式在开发中运行时的工作:

npm start
npm start:webpack

但是在生产中运行时会在renderToString上抛出错误

NODE_ENV=production npm start

webpack成功且没有错误,但在呈现页面时出现错误:

ERROR: TypeError: Cannot set property 'getCurrentStack' of undefined
at setCurrentDebugStack (webpack:///./node_modules/react-dom/cjs/react-dom-server.node.development.js?:1816:48)
at ReactDOMServerRenderer.read (webpack:///./node_modules/react-dom/cjs/react-dom-server.node.development.js?:2225:13)
at renderToString (webpack:///./node_modules/react-dom/cjs/react-dom-server.node.development.js?:2494:29)
at _callee$ (webpack:///./src/server.jsx?:66:49)
at tryCatch (/Users/jasonvillalon/Documents/fun-projects/from-scratch/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (/Users/jasonvillalon/Documents/fun-projects/from-scratch/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as next] (/Users/jasonvillalon/Documents/fun-projects/from-scratch/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:117:21)
at step (webpack:///./src/server.jsx?:27:191)
at eval (webpack:///./src/server.jsx?:27:437)
at new Promise (<anonymous>)

任何人都知道发生了什么事?

最诚挚的问候, 杰森

1 个答案:

答案 0 :(得分:0)

好。我喝了几杯,但请忍受。

问题在于,在Webpack中,您设置了以下内容:

for form_field_name in request.form.keys():
    if form_field_name.endswith('_text'):
        for value in request.form.getlist(form_field_name):
            # process values

但是在您设置的Winblows / DOS命令行上:

let config = {
  mode: "development",
....

或者在您已设置的Linux上

set NODE_ENV=production

或者可能在您设置的webpack.config.js中:

export NODE_ENV=production

要解决此问题,您需要修复顶部:

let config = {
  ...

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

或取消设置NODE_ENV环境变量。

根据以上评论,版权归@Jordan M Alperin所有。