Angular 2 Cannot read property 'config' of null

前端 未结 10 773
执念已碎
执念已碎 2020-12-29 20:30

I have a issue with Angular 2. When i want to start server it get this:

$ ng serve
Cannot read property \'config\' of null
TypeError: Cannot read property \'         


        
相关标签:
10条回答
  • 2020-12-29 20:53

    I found the solution! 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 distention. This solved the issue for me.

    0 讨论(0)
  • 2020-12-29 20:58

    https://angular.io/guide/quickstart

    Step 3: Serve the application Go to the project directory and launch the server.

    content_copy cd my-app ng serve --open

    May be you missed the point 3 (cd my-app)? The start directory have been like: ./my-app/my-app. If start application from other directory we get this error.

    0 讨论(0)
  • 2020-12-29 20:59

    this error is coming due to removal of .angular-cli.json so first add this on root folder. if after that still get error then check static file in .angular-cli.json

    0 讨论(0)
  • 2020-12-29 21:01

    Please add following file at root folder File Name-.angular-cli.json

    {
        "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
        "project": {
            "name": "XXXX"
        },
        "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": [
                    "assets/css/styles.css"
    
                ],
                "scripts": [
                    "assets/js/project.js"      
    
                ],
                "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": {}
        }
    }
    
    0 讨论(0)
  • 2020-12-29 21:03

    The problem could be a mising file .angular-cli.json, do not forget the extension .json which implies the file format. Copy this file from the original project and paste it into your currrent project.

    0 讨论(0)
  • 2020-12-29 21:04

    Probably you remove project into other folder, or delete .angular-cli.json

    Into the root of your app, add: .angular-cli.json

    and paste:

    {
      "$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": {}
      }
    }
    
    0 讨论(0)
提交回复
热议问题