模块构建失败:TypeError:无法读取未定义的属性“sassLoader”

Posted

技术标签:

【中文标题】模块构建失败:TypeError:无法读取未定义的属性“sassLoader”【英文标题】:Module build failed: TypeError: Cannot read property 'sassLoader' of undefined 【发布时间】:2019-02-01 21:36:29 【问题描述】:

我已将 Angular5 更新到 Angular 6。到目前为止,我一直在使用 webpack-dev-server 来启动应用程序。我想让 ng serve 为应用程序提供服务。 但是,当我运行 ng serve 时,我在下面收到此错误:- 在 getLoaderConfig (C:\Work\Dev\Accesslint-Checkins\Accesslint-UI\node_modules\sass-loader\index.js:389:39) 在 Object.module.exports (C:\Work\Dev\Accesslint-Checkins\Accesslint-UI\node_modules\sass-loader\index.js:42:23) ./src/assets/sass/app.scss 中的错误 (./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./node_modules/sass-loader??ref--15-3 !./src/assets/sass/app.scss)

以下是 angular.json,不知何故没有 angular-cli.json :-


  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": 
    "Accesslint-ui": 
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": ,
      "architect": 
        "build": 
          "builder": "@angular-devkit/build-angular:browser",
          "options": 
            "outputPath": "dist/Accesslint-ui",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
			"node_modules/bootstrap/scss/bootstrap.scss",
              "src/styles.scss",   
			  "src/assets/sass/app.scss"
            ],
            "scripts": []
          ,
          "configurations": 
            "production": 
              "fileReplacements": [
                
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            
          
        ,
        "serve": 
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": 
            "browserTarget": "Accesslint-ui:build"
          ,
          "configurations": 
            "production": 
              "browserTarget": "Accesslint-ui:build:production"
            
          
        ,
        "extract-i18n": 
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": 
            "browserTarget": "Accesslint-ui:build"
          
        ,
        "test": 
          "builder": "@angular-devkit/build-angular:karma",
          "options": 
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.css"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          
        ,
        "lint": 
          "builder": "@angular-devkit/build-angular:tslint",
          "options": 
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          
        
      
    ,
    "Accesslint-ui-e2e": 
      "root": "e2e/",
      "projectType": "application",
      "architect": 
        "e2e": 
          "builder": "@angular-devkit/build-angular:protractor",
          "options": 
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "Accesslint-ui:serve"
          ,
          "configurations": 
            "production": 
              "devServerTarget": "Accesslint-ui:serve:production"
            
          
        ,
        "lint": 
          "builder": "@angular-devkit/build-angular:tslint",
          "options": 
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          
        
      
    
  ,
  "defaultProject": "Accesslint-ui"

【问题讨论】:

使用“npm cache clean --force”清除npm缓存并再次运行npm i 【参考方案1】:

另外请检查您在应用程序中使用的 node-sass 和 sass-loader 版本是什么。尝试使用可以解决此问题的最新版本。

这是我的应用程序中使用的版本

node-sass : 4.9.3
sass-loader: 7.1.0

【讨论】:

嗨,Suresh,抱歉耽搁了。安装了最新的 node-sass 和 sass-loader 仍然有同样的问题。还清除了缓存。

以上是关于模块构建失败:TypeError:无法读取未定义的属性“sassLoader”的主要内容,如果未能解决你的问题,请参考以下文章

模块构建失败:TypeError:无法读取 Object.module.exports 处未定义的属性“上下文”

NuxtJS Apollo 模块 TypeError:无法读取未定义的属性“$apolloHelpers”

错误:捆绑失败:TypeError:无法读取未定义的属性“transformFile”,React Native

angular_1.default.module Uncaught TypeError:无法读取未定义的属性“模块”

为啥这些 Jest 测试失败了? TypeError:无法读取未定义的属性“应用”

ModuleBuildError:模块构建失败:TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。接收类型未定义