You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 11执行ng serve -o报错,mini-css-extract-plugin问题求助

Angular 11项目ng serve报错(mini-css-extract-plugin相关)解决方案
  • 锁定兼容版本的mini-css-extract-plugin
    Angular 11适配的webpack版本为4.x,对应mini-css-extract-plugin需使用^0.9.0版本,执行以下命令安装:
    npm install mini-css-extract-plugin@^0.9.0 --save-dev

  • 清理依赖缓存并重装

    • 删除本地依赖文件夹:rm -rf node_modules(Windows系统执行rmdir /s /q node_modules)
    • 删除依赖锁定文件:rm package-lock.json
    • 重新安装全部依赖:npm install
  • 校验angular.json配置
    确认项目根目录的angular.json中,build配置的CSS提取设置正确,Angular 11默认启用该配置,若有自定义修改需确保:

"build": {
  "options": {
    "extractCss": true,
    // 其他配置项...
  }
}
  • 同步Angular CLI版本
    Angular 11需搭配同版本的CLI,执行命令安装对应稳定版:
    npm install @angular/cli@11.2.19 --save-dev

  • 排查第三方依赖冲突
    部分第三方库可能引入高版本的mini-css-extract-plugin,执行npm ls mini-css-extract-plugin查看依赖树定位冲突包,通过resolutions字段强制锁定版本:

    1. 安装依赖锁定工具:npm install npm-force-resolutions --save-dev
    2. 在package.json中添加:
    "resolutions": {
      "mini-css-extract-plugin": "^0.9.0"
    }
    
    1. 重新执行npm install

内容的提问来源于stack exchange,提问作者Gabriel Duarte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 00:06:18