【问题标题】:MiniCssExtractPlugin error when I run npm run build运行 npm run build 时出现 MiniCssExtractPlugin 错误
【发布时间】:2022-01-21 23:20:54
【问题描述】:

我正在尝试在我的 reactjs 网站上运行“Npm Run Build”,但我不断收到此错误:

/usr/local/lib/node_modules/react-scripts/config/webpack.config.js:664
    new MiniCssExtractPlugin({
    ^

TypeError: MiniCssExtractPlugin is not a constructor

我查看了其他解决这个问题的方法,比如运行这个命令:

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

另一个说删除 node_modules 和 package.lock.json,这两个都不适合我。

这是我的 package.json:

{
   "name": "web-client",
   "version": "0.1.0",
   "private": true,
   "dependencies": {
      "@material-ui/core": "^4.12.3",
      "@testing-library/jest-dom": "^5.14.1",
      "@testing-library/react": "^11.2.7",
      "@testing-library/user-event": "^12.8.3",
      "axios": "^0.21.1",
      "bootstrap": "^5.1.0",
      "emailjs-com": "^3.2.0",
      "get-video-duration": "^4.0.0",
      "nodemailer": "^6.7.2",
      "prop-types": "^15.7.2",
      "react": "^17.0.2",
      "react-bootstrap": "^1.6.1",
      "react-dom": "^17.0.2",
      "react-dropzone": "^11.3.4",
      "react-icons": "^4.2.0",
      "react-modal": "^3.14.3",
      "react-router-dom": "^5.2.0",
      "react-s3-uploader": "^5.0.0",
      "react-scripts": "4.0.3",
      "styled-components": "^5.3.0",
      "web-vitals": "^1.1.2"
   },
  "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"
]
},
   "resolutions": {
"mini-css-extract-plugin": "2.4.5"
 }
}

有人知道为什么这不起作用吗??

【问题讨论】:

    标签: javascript node.js reactjs npm mini-css-extract-plugin


    【解决方案1】:

    这是因为版本 2.5.0 的更新。

    版本 2.5.1 应该可以解决这个问题,所以如果可以的话,请安装它。

    如果你不能,请尝试两件事:

    可能由于缓存问题,resolutions 不起作用:

    rm -rf node_modules && npm cache clean --force && npm i

    还是不行?更改导入:

    const { default: MiniCssExtractPlugin } = require('mini-css-extract-plugin');

    【讨论】:

      猜你喜欢
      • 2021-03-03
      • 2021-08-10
      • 1970-01-01
      • 2023-02-02
      • 2022-06-16
      • 2021-04-10
      • 2022-01-23
      • 1970-01-01
      • 2020-06-15
      相关资源
      最近更新 更多