拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 运行命令“npmrunbuild”时出错,错误“TypeError:MiniCssExtractPlugin不是建构式”

运行命令“npmrunbuild”时出错,错误“TypeError:MiniCssExtractPlugin不是建构式”

白鹭 - 2022-01-23 2018 0 0

我正在使用 react 创建一个应用程序,它运行良好,npm start但是当我尝试构建应用程序时,这显示以下错误。

PS D:\ ****\ **\*\profile> npm run build

> profile@0.1.0 build
> react-scripts build

D:\ ****\ **\profile\node_modules\react-scripts\config\webpack.config.js:664
        new MiniCssExtractPlugin({
        ^

TypeError: MiniCssExtractPlugin is not a constructor
    at module.exports (D:\Documents\Project\React\profile\node_modules\react-scripts\config\webpack.config.js:664:9)
    at Object.<anonymous> (D:\Documents\Project\React\profile\node_modules\react-scripts\scripts\build.js:58:16)
    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)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

我正在使用

包裹名字 版本
节点 16.13.2
npm 8.1.2
npx 8.1.2

这是我的package.json档案。

{
  "name": "profile",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "5.0.0",
    "web-vitals": "^2.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我也尝试重新安装整个节点包,但我一次又一次地收到这个错误。

uj5u.com热心网友回复:

mini-css-extract-plugin 在 2.5.0 版中有更新。我通过添加临时修复它package.json

 "overrides": {
    "mini-css-extract-plugin": "2.4.5"
  }

对于您的npm版本,请先尝试:

npm i -D --save-exact mini-css-extract-plugin@2.4.5
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *