Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined

Posted

技术标签:

【中文标题】Ng add @nrwl/workspace throws Cannot read property \'paths\' of undefined【英文标题】:Ng add @nrwl/workspace throws Cannot read property 'paths' of undefinedNg add @nrwl/workspace throws Cannot read property 'paths' of undefined 【发布时间】:2020-11-06 12:41:26 【问题描述】:

我只是使用 angular cli 创建一个项目,然后运行命令“ng add @nrwl/workspace”将其更改为 nrwl 工作区。但我收到以下错误“无法读取未定义的属性'路径'”。

我在互联网上搜索了一下,发现有人有类似的错误,但他的错误是在 angular.json 中的测试丢失了我的 angular.json 中有所需的一切。

是否有人可以查看我的 json 文件并说出可能导致此错误的原因。我正在使用 nrwl 和 angular 的最新版本

Angula.json

   
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": 
    "moniesta-admin": 
      "projectType": "application",
      "schematics": 
        "@schematics/angular:component": 
          "style": "scss"
        
      ,
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": 
        "build": 
          "builder": "@angular-devkit/build-angular:browser",
          "options": 
            "outputPath": "dist/moniesta-admin",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.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,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                ,
                
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                
              ]
            
          
        ,
        "serve": 
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": 
            "browserTarget": "moniesta-admin:build"
          ,
          "configurations": 
            "production": 
              "browserTarget": "moniesta-admin:build:production"
            
          
        ,
        "extract-i18n": 
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": 
            "browserTarget": "moniesta-admin:build"
          
        ,
        "test": 
          "builder": "@angular-devkit/build-angular:karma",
          "options": 
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          
        ,
        "lint": 
          "builder": "@angular-devkit/build-angular:tslint",
          "options": 
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          
        ,
        "e2e": 
          "builder": "@angular-devkit/build-angular:protractor",
          "options": 
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "moniesta-admin:serve"
          ,
          "configurations": 
            "production": 
              "devServerTarget": "moniesta-admin:serve:production"
            
          
        
      
    ,
  "defaultProject": "moniesta-admin"

【问题讨论】:

v10 是否发生了这种情况?如果问题在 v10 中仍然存在,您是否可以在 nrwl/nx 存储库中提出问题。 【参考方案1】:

我也遇到过这种问题,我是这样解决的:在根目录tsconfig.json中需要一个paths参数。 像这样:


  "compilerOptions": 
    "paths": 
    
  

【讨论】:

以上是关于Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined的主要内容,如果未能解决你的问题,请参考以下文章

ng表示不打印数据

如何使用ng-if和tr-tag以及ng-repeat?

angularjs的ng-repeat循环列表中序号怎么写

AngularJS - ng-repeat只显示一次标题

如何从外部原理图中调用 ng add

ng-show