Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: Cannot set property 'lastEffect' of null

I am getting below error in production. Looks like it’s related to uglisify Webpack plugin I can’t find solution to resolve it.

Webpack config:

    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'));

Versions:

"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"

Error:

  React: Cannot set property 'lastEffect' of null
like image 679
Hemadri Dasari Avatar asked Nov 17 '18 05:11

Hemadri Dasari


2 Answers

If you update to uglifyjs-webpack-plugin version 2.2.0 the problem is fixed.

like image 188
jmargolisvt Avatar answered Nov 11 '22 03:11

jmargolisvt


This is caused by uglifyjs-webpack-plugin version 2.0.1 in React 16.7.0-alpha as it breaks the new hook feature of React.

You can try using the terser plugin. Here is the link: https://github.com/webpack-contrib/terser-webpack-plugin

like image 43
Rohan Dhar Avatar answered Nov 11 '22 02:11

Rohan Dhar