8

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"
 }
1

5 Answers 5

17

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Just open another ng project with that file present in a separate VS Code window, and simply drag and droped the file to the other ng project where it was missing. The file is at the root level.
9

Fixed the issue by copying .angular-cli.json file to the new directory.

Per request, more details:

After creating your project, but prior to moving it to a different directory you will notice a .angular-cli.json file was created, visible from the command line via ls -al. This file is needed in the root directory of your project. It should be moved there via mv .angular-cli.json . and should be added to source control so others cloning the project have this file.

2 Comments

can you please explain more detail how you fixed , thanks
You should copy .angular-cli.json file to root folder of Your web application.
4

i found the solution ! :D

in my case i moved the project to another directory there is a hidden file called .angular-cli,

show the hidden file in the old project and copy this file and paste it in the new destination.

this is solved the issue for me.

Comments

0

do not forget to install npm packages,
run npm i in root directory

Comments

0

After angular 5, when we create either zip or copy of project, on that time angular-cli.json file not included in zip or copy folder and we send this zip or folder to another friend or itself but after install angular project. we run ng serve but unfortunately it given error cannot read property config of null

so solve this issue, send also angular-cli.json file or you can copy and paste into new project(error project).

*angular-cli.json = its hidden file .....must be remembered.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.