我在生产中遇到了错误。看起来与uglisify Webpack插件有关,我找不到解决方案。
Webpack配置:
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
module.exports = {
mode: "production",
entry: "./index.tsx",
resolve: {
extensions: [".js", ".tsx"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: "ts-loader",
options: {
transpileOnly: true
}
}
}
]
},
optimization: {
minimizer: [new UglifyJSPlugin()]
}
};
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
const TestComponent = () => {
React.useEffect(() => {});
return null;
};
ReactDOM.render(<TestComponent />, document.getElementById('app'));
版本:
"react": "^16.7.0-alpha.0",
"react-dom": "^16.7.0-alpha.0",
"uglifyjs-webpack-plugin": "^2.0.1",
"webpack": "4.19.0",
"webpack-cli": "^3.1.2"
错误:
React: Cannot set property 'lastEffect' of null
答案 0 :(得分:10)
这是由于React 16.7.0-alpha中的uglifyjs-webpack-plugin版本2.0.1引起的,因为它破坏了React的新钩子功能。
您可以尝试使用terser插件。链接在这里: https://github.com/webpack-contrib/terser-webpack-plugin
答案 1 :(得分:3)
如果您更新到uglifyjs-webpack-plugin版本2.2.0,则此问题已解决。