Faced the same Issue. While running ngserve you should be in the apps directory. To confirm(on GIT BASH : you will have (master) after the directory path at gitbash prompt, if you are at app directory.)
The problem I had was that I followed the cli's advice to switch to yarn package management.
Then while following a tutorial I did npm install --save bootstrap, and after that point the error started appearing. Afterwards I did yarn add xxx of course and it worked.
To restore the project's state I removed node_modules and package-lock.json as per this answer and then run yarn install
If anyone is running into this in 2018, the thing that finally worked for me was to go into the my-app I created with ng new my-app, and THEN run ng serve This has to do with it needing the dependencies and devDependencies located in my-app/package.json instead of root/package.json. They are two separate files.
Even if I copied the all the dependencies to my root folder's package.json, I would also have to go in and manually change the path locations for the config files and such to go into my-app/*. It is much easier to just go into my-app/ and run ng serve there to let it all work like it is supposed to.
So these steps should work for anyone:
rm -rf <previous-app> // Whatever your previous app was called, if you had one.
Then run following command it will update npm packages.
npm update
Later start project executing following command.
ng serve
Above steps worked for me.
Faced the same Issue. While running ngserve you should be in the apps directory. To confirm(on GIT BASH : you will have (master) after the directory path at gitbash prompt, if you are at app directory.)
To solve this problem.
cd projectName
npm update
ng serve -o
For example :
The problem I had was that I followed the cli's advice to switch to yarn package management.
Then while following a tutorial I did
npm install --save bootstrap
, and after that point the error started appearing. Afterwards I didyarn add xxx
of course and it worked.To restore the project's state I removed
node_modules
andpackage-lock.json
as per this answer and then runyarn install
If anyone is running into this in 2018, the thing that finally worked for me was to go into the my-app I created with
ng new my-app
, and THEN runng serve
This has to do with it needing the dependencies and devDependencies located inmy-app/package.json
instead ofroot/package.json
. They are two separate files.Even if I copied the all the dependencies to my root folder's
package.json
, I would also have to go in and manually change the path locations for the config files and such to go intomy-app/*
. It is much easier to just go intomy-app/
and runng serve
there to let it all work like it is supposed to.So these steps should work for anyone:
rm -rf <previous-app>
// Whatever your previous app was called, if you had one.sudo rm -rf node_modules
rm -f package-lock.json
npm install
ng new my-app
cd my-app
ng serve
While running
ng serve
you should be in the app's/project's directory.If you run the command in another directory you get the error: