简体   繁体   中英

Can't run npm install as it does not contain a package.json file

Here is my story: I wanted to upgrade my local @angular-cli version. I did it and it caused a lot of problems (Cannot find module '@angular/compiler-cli/ngcc' etc.), because of that, I tried many different ways to solve the problem, but it didn't work. Then I moved to another project and when I run ng serve it had a problem about Node Sass. I tried to solve it but now it says The serve command requires to be run in an Angular project, but a project definition could not be found.

And I cannot run npm install as it says: Could not install from "node_modules/base-env/resolve-file@github:jonschlinkert/..." as it does not contain a package.json file.

How on earth can I solve this problem?

This happens because time ago, Angular projects were defined by an angular-cli.json file. In latest versions, that file has been renamed in angular.json . If you only updated your cli version without changing any code, then the script is looking for a angular.json but, since it doesn't find any, it throws an error stating that that's not an angular project.

To solve it, you can run:

ng update @angular/cli

Which will migrate all your configuration towards the new format.

If this doesn't work too, the easiest way to solve any problem, by experience, is to run again

ng new <project-name>

In a new folder, and copy/paste the src/app content

ng update added

"@types/jasmine": "~2.8ng update @angular/material@8.8"

to my package.json. removing this row fixed my problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM