gpt4 book ai didi

reactjs - ReactDOM RSS renderToString 制作错误

转载 作者:行者123 更新时间:2023-12-03 13:39:02 25 4
gpt4 key购买 nike

我为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>)

有人知道发生了什么事吗?

最诚挚的问候,杰森

最佳答案

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

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

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

set NODE_ENV=production

或者在您已设置的 Linux 上

export NODE_ENV=production

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

let config = {
...

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

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

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

或取消设置 NODE_ENV 环境变量。

上面的评论归功于@Jordan M Alperin。

关于reactjs - ReactDOM RSS renderToString 制作错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49154914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com