Angular: ng new error when I create an angular pro

2019-07-11 02:02发布

问题:

I have this error using ng new project_name:

An invalid configuration file was found ['angular.json']. Please delete the file before running the command.

I am getting this error I don't know how to get the solution.

I uninstalled @angular/cli and installed again

npm clean cache doesnt work too (I dont know if it is problem of my npm version

npm version is 6.4.1    
node version is 8.11.1

what do i need to solve the problem?

回答1:

The problem seems to be the _ in project_name resulting in the following error:

Schematic input does not validate against the Schema: {"name":"project_name","version":"6.0.1","newProjectRoot":"projects","skipInstall":false,"linkCli":false,"skipGit":false,"commit":null}
Errors:

  Data path ".name" should match format "html-selector".

Replace _ e.g. with -.

Further readings:

  • Error when creating new project with Angular-CLI 6.1.2
  • Style Guide


回答2:

I deleted the file in c:\users\XXX\.angular.json and it was running ok.



回答3:

Run following if file is hidden. Open Terminal, run mv /Users/shivammishra/.angular.json /Users/shivammishra/angular.json.txt. mv command will move the file to new location (angular.json.txt) and you can then delete.