首页 > 解决方案 > 试图 webpack 反应项目得到 Uncaught TypeError: Cannot read property 'dispose' of undefined

问题描述

我试图使用这个 webpack.config.js 对 webpack 反应项目:

const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");

module.exports = {
  mode: "production",
  entry: "./app/src/plugin.js",
  output: {
    filename: "build/static/js/bundle-project.min.js",
    libraryTarget: "commonjs"
  },
  node: {
    fs: "empty"
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"]
      },
      {
        test: /\.svg$/,
        loader: "svg-inline-loader"
      },
      {
        test: /\.(png|woff|woff2|eot|ttf|svg)$/,
        loader: "url-loader?limit=100000"
      },
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: "babel-loader",
        options: {
          presets: ["@babel/preset-react", "@babel/preset-env"],
          plugins: [
            "@babel/plugin-syntax-dynamic-import",
            "@babel/plugin-proposal-class-properties",
            "@babel/plugin-transform-modules-commonjs"
          ]
        }
      }
    ]
  },
  plugins: [
    new TerserPlugin({
      parallel: true,
      terserOptions: {
        ecma: 6
      }
    })
  ],
  resolve: {
    alias: {
      utils: path.resolve("./src/utils"),
      "user-abilities": path.resolve("./src/user-abilities"),
      shared: path.resolve("./src/shared"),
      components: path.resolve("./src/components"),
      store: path.resolve("./src/store")
    }
  },
  externals: {
    react: "commonjs react"
  }
};

然后我做 npm 发布并将包导入到另一个项目中,使用

从 @my-repo-package 导入 Main

尝试在不同的项目中呈现包时出现此错误:

在此处输入图像描述

标签: javascriptreactjsnpmwebpack

解决方案


推荐阅读