React Scripts 和 terser-webpack-plugin 的问题

issue with React Scripts and terser-webpack-plugin

从昨天开始,当 运行 我的 create-react-app 中的 'npm start' 脚本时,我突然开始收到这个错误。我以前从未遇到过这个问题,也没有更改任何配置或 package.json 文件进出反应脚本。 terser-webpack-plugin 安装在该位置,其“主要”是:

"main": "dist/index.js",

我尝试重新安装 node_modules 但没有成功。我也在这里尝试了解决方案:Use latest terser-webpack-plugin with Webpack5

      throw err;
      ^

Error: Cannot find module 'Z:\Documents\chat-test\my-app\node_modules\terser-webpack-plugin\dist\index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:353:19)
    at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (Z:\Documents\chat-test\my-app\node_modules\react-scripts\config\webpack.config.js:18:22)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32) {
  code: 'MODULE_NOT_FOUND',
  path: 'Z:\Documents\chat-test\my-app\node_modules\terser-webpack-plugin\package.json',
  requestPath: 'terser-webpack-plugin'
}

可能的修复,尝试其中之一或两者:

  • npm i --save-dev terser-webpack-plugin
  • 删除 package.lock 和 运行 npm i