I want to create an angular 2 App with angular cli
I have written in the cmd:
npm install angular-cli -g
then:
ng firstngapp
https://i.stack.imgur.com/0afMx.jpg
https://i.stack.imgur.com/nP17A.jpg
I don't understand the problem
npm install
Try to run
npm install
in the project folder
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:
You seem to not be depending on "@angular/core". This is an error.
Delete your node modules , Check your package.json
file should have the @angular/core
and reinstall it with npm i
.
Delete node_modules folder and package-lock.json file. Then run following command it will update npm packages. npm update Later start project executing following command. ng serve
Above steps worked for me.
May help you.
Delete All folders you have created previously
Create fresh folder
Then try navigate to that folder from command "cd foldername"
then try to install "npm install"
This will solve you problem.
from terminal
> cd myProjectPath
myProjectPath > npm install
Below steps worked for me:
1) Delete the node_modules/
folder and package-lock.json
file.
2) npm install
3) ng serve
I don't know if it is still an issue. I was experiencing the same nuisance with @angular/cli v1.1.2
on npm 4.1.2
. I deleted the node_modules
directory and then went on to updating npm
(since this was a common cause in the past).
I wanted to upgrade npm
to 5.0.3
(latest) but since I was using nvm
it seems to have messed up the libraries. Thus, I reinstalled node
.
Then, I went with
npm cache clean
npm rebuild
npm install - This one several times, since every time it threw an error with a different package
In the end, every package was fine.
Hope this helps.
the fix for me was
npm link
ng build
https://i.stack.imgur.com/P5bLf.png
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.
sudo rm -rf node_modules
rm -f package-lock.json
npm install
ng new my-app
cd my-app
ng serve
previous-app
After doing your commands I get a You cannot use the new command inside an Angular CLI project.
error while doing ng new my-app
rm -rf <previous app>
if you had a previous app that is creating this problem. substitute the name of you app in here. rm -rf
removes recursively by force the entire directory's contents
Run the npm update after installing all peer dependencies and it will work.
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.)
This is how I solved this problem.
I first ran npm install @angular/core
.
Then I ran npm install --save
.
When both installs had successfully completed I ran npm serve
and received an error saying
"Versions of @angular/compiler-cli and typescript could not be determined.
The most common reason for this is a broken npm install.
Please make sure your package.json contains both @angular/compiler-cli and typescript in
devDependencies, then delete node_modules and package-lock.json (if you have one) and
run npm install again."
I then deleted my node_modules folder as well as my package-lock.json folder.
After I deleted those folders I ran npm install --save
once more.
I ran npm start
and received another error. This error said Error: Cannot find module '@angular-devkit/core'
.
I ran npm install @angular-devkit/core --save
.
Finally, I ran npm start
and the project started!
I got the same issue, and the reason is
when you run ng new app-name it will create a new directory with app name and install everything in that. after running the above command, human tendency is to run ng serve and because your app is in sub directory it will not find package.json and throw the mentioned error.
Solution is pretty simple. just move to the sub directory and then run ng serve
You create new project with:
ng new firstngapp
In your example you are missing new
. This would create folder, generate files and run npm install
for you. It seems that you've created folder but there's no Angular CLI app in it.
And for starting the app use:
ng serve
npm start
is only used if you have ejected from cli.
After trying to no avail:
npm install
npm update
ng serve
npm install -g @angular/cli worked for me
I had the same issue and along with removing the node_modules and reinstalling I needed to remove package-lock.json first.
I was getting the same error when I tried to run "ng serve" after that I saw some suggetions one of the techie told me to update my npm.I did that as well then I got this screen after entering "ng server"
""Versions of @angular/compiler-cli and typescript could not be determined. The most common reason for this is a broken npm install. Please make sure your package.json contains both @angular/compiler-cli and typescript in devDependencies, then delete node_module and package-lock.json(if you have one) and Run npm install again.""
After performing all the actions now its working correctly...and getting message "Compiled Successfully."
You need to run the ng server from the c:\project\angular-src location. Not just the root of your project.
ng serve
must be run from the root of the folder, since that's where the package.json
file defining this script is.
Executing ng new --skip-install PROJECT_NAME and then manually going into the created folder and typing npm install. https://github.com/angular/angular-cli/issues/3906
In my case the following worked:
rm -rf node_modules
rm package-lock.json
npm install
Hence the npm install
, not update.
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
Versions of @angular/compiler-cli and typescript could not be determined. The most common reason for this is a broken npm install.
Please make sure your package.json contains both @angular/compiler-cli and typescript in devDependencies, then delete node_modules and package-lock.json (if you have one) and run npm install again.
This happened to me when I was mixing package managers. My project was generated with Yarn, and after that, I added a couple of dependencies using npm install (this created the package-lock.json with only added dependencies).
Apparently, ng serve used package-lock.json and couldn't find Angular dependencies there. After I started using only Yarn, i.e. yarn add instead of npm install, the error was gone.
**You should be in the newly created YOUR_APP folder before you hit the ng serve command **
Lets start from fresh,
1) install npm
2) create a new angular app ( ng new <YOUR_APP_NAME>
)
3) go to app folder (cd YOUR_APP_NAME
)
4) ng serve
I hope it will resolve the issue.
To solve this problem.
Step1: cd projectName Step2: npm update Step3: ng serve -o
https://i.stack.imgur.com/MPMZm.png
For ng serve you need to be inside that directory
ashish@ashish-Inspiron-3521:~/Angular$ ng new FireStore
create FireStore/README.md (1025 bytes)
create FireStore/.angular-cli.json (1245 bytes)
create FireStore/.editorconfig (245 bytes)
create FireStore/.gitignore (544 bytes)
create FireStore/src/assets/.gitkeep (0 bytes)
create FireStore/src/environments/environment.prod.ts (51 bytes)
create FireStore/src/environments/environment.ts (387 bytes)
create FireStore/src/favicon.ico (5430 bytes)
create FireStore/src/index.html (296 bytes)
create FireStore/src/main.ts (370 bytes)
create FireStore/src/polyfills.ts (3114 bytes)
create FireStore/src/styles.css (80 bytes)
ashish@ashish-Inspiron-3521:~/Angular$ ng serve
You seem to not be depending on "@angular/core". This is an error.
How I solved this using cmd
ashish@ashish-Inspiron-3521:~/Angular$ cd FireStore/
Now Do cmd
ashish@ashish-Inspiron-3521:~/Angular/FireStore$ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Success story sharing