Angular CLI:无法读取 null 的属性“config" [英] Angular CLI: Cannot read property 'config' of null

查看:29
本文介绍了Angular CLI:无法读取 null 的属性“config"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近将我的应用程序从 Angular 2.3.0 升级到 Angular 4.0.3.在此过程中还升级了 angular-cli.如果项目克隆到新目录,则会抛出:

<块引用>

无法读取 null 的属性 'config' 类型错误:无法读取属性'config' 为空在 Class.run (/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/tasks/build.js:16:56)在 Class.run (/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/commands/build.js:143:26)在课堂上.(/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/ember-cli/lib/models/command.js:134:17)在 process._tickCallback (internal/process/next_tick.js:109:7)

package.json

脚本":{"ng": "ng","start": "ng serve","build": "ng build","test": "ng 测试","lint": "ng lint","e2e": "ng e2e"},私人":真的,依赖关系":{"@angular/animations": "^4.0.3","@angular/cli": "^1.0.1","@angular/common": "^4.0.3","@angular/compiler": "^4.0.3","@angular/compiler-cli": "^4.0.3","@angular/core": "^4.0.3","@angular/forms": "^4.0.3","@angular/http": "^4.0.3","@angular/material": "^2.0.0-beta.3","@angular/platform-b​​rowser": "^4.0.3","@angular/platform-b​​rowser-dynamic": "^4.0.3","@angular/platform-server": "^4.0.3","@angular/router": "^4.0.3","core-js": "^2.4.1","hammerjs": "^2.0.8","rxjs": "^5.2.0","打字稿": "^2.2.2",zone.js":^0.8.4"},开发依赖":{"@angular/cli": "^1.0.1","@angular/compiler-cli": "^2.4.0","@types/jasmine": "2.5.38","@types/node": "~6.0.60","codelyzer": "~2.0.0","jasmine-core": "~2.5.2","jasmine-spec-reporter": "~3.2.0",业力":~1.4.1","karma-chrome-launcher": "~2.0.0","karma-cli": "~1.0.1","karma-coverage-istanbul-reporter": "^0.2.0","karma-jasmine": "~1.1.0","karma-jasmine-html-reporter": "^0.2.2",量角器":~5.1.0","ts-node": "~2.0.0","tslint": "~4.4.2",打字稿":~2.2.2"}

解决方案

这是直到 Angular v5 的有效解决方案,因为在 v6 中,文件的位置更改为 angular.json,并且内容也更改了

强>

创建一个名为 .angular-cli.json 的新文件并插入:

<代码>{"$schema": "./node_modules/@angular/cli/lib/config/schema.json",项目": {"name": "PROJECT_NAME"},应用": [{"root": "src","outDir": "dist",资产":[资产",favicon.ico"],"index": "index.html","main": "main.ts","polyfills": "polyfills.ts","test": "test.ts","tsconfig": "tsconfig.app.json","testTsconfig": "tsconfig.spec.json",前缀":应用程序",风格":[样式.css"],脚本":[],"environmentSource": "environments/environment.ts",环境":{"dev": "环境/environment.ts","prod": "环境/environment.prod.ts"}}],e2e":{量角器":{配置":./protractor.conf.js"}},棉绒":[{项目":src/tsconfig.app.json"},{项目":src/tsconfig.spec.json"},{项目":e2e/tsconfig.e2e.json"}],测试": {业力":{配置":./karma.conf.js"}},默认值":{"styleExt": "css",成分": {}}}

如果您从 angular-cli 创建新项目,您还会找到此 json 的副本.

Recently upgraded my application from Angular 2.3.0 to Angular 4.0.3. In the process also upgraded angular-cli. If project cloned to a new directory, it is throwing:

Cannot read property 'config' of null TypeError: Cannot read property 'config' of null at Class.run (/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/tasks/build.js:16:56) at Class.run (/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/commands/build.js:143:26) at Class. (/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/ember-cli/lib/models/command.js:134:17) at process._tickCallback (internal/process/next_tick.js:109:7)

package.json

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.0.3",
    "@angular/cli": "^1.0.1",
    "@angular/common": "^4.0.3",
    "@angular/compiler": "^4.0.3",
    "@angular/compiler-cli": "^4.0.3",
    "@angular/core": "^4.0.3",
    "@angular/forms": "^4.0.3",
    "@angular/http": "^4.0.3",
    "@angular/material": "^2.0.0-beta.3",
    "@angular/platform-browser": "^4.0.3",
    "@angular/platform-browser-dynamic": "^4.0.3",
    "@angular/platform-server": "^4.0.3",
    "@angular/router": "^4.0.3",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.2.0",
    "typescript": "^2.2.2",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.1",
    "@angular/compiler-cli": "^2.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.4.2",
    "typescript": "~2.2.2"
 }

解决方案

This is a working solution until Angular v5 because inside v6, the location of the file changed to angular.json, and changed also the content

Create a new file called .angular-cli.json and insert:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "PROJECT_NAME"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

You will also find a copy of this json if you create a new project from angular-cli.

这篇关于Angular CLI:无法读取 null 的属性“config"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆