模块构建错误(来自./node_modules/@angular-devkit/build-angular/node_modules/mini-css-extract-plugin/dist/loader.js)

时间:2019-12-26 14:13:01

标签: angular

我运行ng build --prod时遇到此错误。它可以毫无错误地服务,但无法构建。我将与之联系

ERROR in Module build failed (from ./node_modules/@angular-devkit/build-angular/node_modules/mini-css-extract-plugin/dist/loader.js):       
TypeError: Cannot read property 'replace' of undefined
    at normalizeBackSlashDirection (C:\project\tea supply chain mangement system\test2\node_modules\webpack\lib\RequestShortener.js:16:17)  
    at new RequestShortener (C:\project\tea supply chain mangement system\test2\node_modules\webpack\lib\RequestShortener.js:26:15)
    at new Compiler (C:\project\tea supply chain mangement system\test2\node_modules\webpack\lib\Compiler.js:195:27)
    at Compiler.createChildCompiler (C:\project\tea supply chain mangement system\test2\node_modules\webpack\lib\Compiler.js:548:25)        
    at Compilation.createChildCompiler (C:\project\tea supply chain mangement system\test2\node_modules\webpack\lib\Compilation.js:2100:24) 
    at Object.pitch (C:\project\tea supply chain mangement system\test2\node_modules\@angular-devkit\build-angular\node_modules\mini-css-extract-plugin\dist\loader.js:89:43)

我的依赖项:

"dependencies": {
  "@agm/core": "^1.1.0",
    "@angular/animations": "8.2.14",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "8.2.14",
    "@angular/compiler": "8.2.14",
    "@angular/core": "^8.2.14",
    "@angular/http": "^7.2.15",
    "@angular/material": "^8.2.3",
    "@angular/router": "8.2.14",
       ....
    "web3": "^1.2.4",
    "zone.js": "0.9.1"   
},   
   "devDependencies": {  
   "@angular-builders/custom-webpack": "^8.4.1",
    "@angular-builders/dev-server": "^7.3.1",
    "@angular-devkit/build-angular": "^0.803.21",
    "@angular-devkit/architect": "^0.803.21",
    "@angular/cli": "^8.3.21",
    "@angular/compiler-cli": "^8.2.14",
    "@angular/language-service": "8.2.14",
    .....
  }

如何解决此错误?

3 个答案:

答案 0 :(得分:1)

https://github.com/webpack-contrib/mini-css-extract-plugin/issues/186上的讨论包括以下语句:当任何组件具有其数组值长度大于1的styleUrls属性时,就会发生此错误。

我在一个应用程序中对此进行了验证,在该应用程序中,将此属性的值减小为长度为1的数组会使错误消失。

答案 1 :(得分:0)

在我的情况下,某些CSS无法正常工作,这就是为什么出现此错误的原因。我一一检查就发现了。因为此错误隐藏了其他错误。

答案 2 :(得分:0)

我遇到这个错误是因为我在 angular.json 文件中放置了“”是样式列表的错误。我想添加 css 文件并开始输入,但我以另一种方式进行了操作,并且将这个 "" 留在了那里。

"styles": [
  "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
  "src/styles.css",
  "node_modules/bootstrap/dist/css/bootstrap.min.css",
  "" /* <--- this line breaks everything */
],