150

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

but it show me an error when I write npm start ! the error image

Files image

I don't understand the problem

Jeffrey Roosendaal
  • 6,872
  • 8
  • 37
  • 55

27 Answers27

194

Try to run

npm install

in the project folder (not root folder)

Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159
galvan
  • 7,400
  • 7
  • 38
  • 55
80

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.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
niranjan pb
  • 1,125
  • 11
  • 14
16

Delete your node modules , Check your package.json file should have the @angular/core and reinstall it with npm i.

SeleM
  • 9,310
  • 5
  • 32
  • 51
15
  1. Delete node_modules folder and package-lock.json file.
  2. Then run following command it will update npm packages.

    npm update

  3. Later start project executing following command.

    ng serve

Above steps worked for me.

Dinesh Kumar
  • 307
  • 1
  • 3
  • 9
sabin
  • 841
  • 12
  • 15
8

Below steps worked for me:

1) Delete the node_modules/ folder and package-lock.json file.

2) npm install

3) ng serve

rhavelka
  • 2,283
  • 3
  • 22
  • 36
Ashish168
  • 162
  • 4
  • 14
8

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.

Ajit Kumar
  • 590
  • 1
  • 8
  • 17
7

from terminal

 > cd myProjectPath
 myProjectPath > npm install
Pooja
  • 356
  • 2
  • 11
5

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.

4

the fix for me was

npm link
ng build 

enter image description here

grepit
  • 21,260
  • 6
  • 105
  • 81
3

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

Dan
  • 451
  • 3
  • 13
  • Can you explain what does rm -rf I don't remember if and why I did a `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` – Revolucion for Monica Apr 04 '18 at 14:05
  • @Marine1 You cannot create a new Angular app inside of an Angular app. and only run `rm -rf ` 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_ – Dan Apr 18 '18 at 19:49
2

Run the npm update after installing all peer dependencies and it will work.

2

I got the same issue, and the reason is

  1. when you run ng new app-name it will create a new directory with app name and install everything in that.
  2. 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

Amir
  • 8,821
  • 7
  • 44
  • 48
abhirathore2006
  • 3,317
  • 1
  • 25
  • 29
2

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.)

Learner
  • 99
  • 3
  • 14
2

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 Stand With Israel
  • 1,971
  • 16
  • 30
1

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.

Miroslav Jonas
  • 5,407
  • 1
  • 27
  • 41
1

After trying to no avail:

  • npm install
  • npm update
  • ng serve

npm install -g @angular/cli worked for me

0

I had the same issue and along with removing the node_modules and reinstalling I needed to remove package-lock.json first.

RollWhisTler
  • 341
  • 1
  • 3
  • 10
0

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."

Irshad
  • 1
  • 1
0

You need to run the ng server from the c:\project\angular-src location. Not just the root of your project.

Tony B
  • 41
  • 1
  • 8
  • OP might not have c:\project\angular-src folder. And no, you answer makes no sense. `ng serve` must be run from the root of the folder, since that's where the `package.json` file defining this script is. – Miroslav Jonas Jan 24 '18 at 19:54
0

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

rsapru
  • 688
  • 14
  • 30
0

In my case the following worked:

rm -rf node_modules
rm package-lock.json
npm install

Hence the npm install, not update.

Lars
  • 340
  • 4
  • 19
0

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

bottlenecked
  • 2,079
  • 2
  • 21
  • 32
0

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.

0

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.

Yakov Fain
  • 11,972
  • 5
  • 33
  • 38
0

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/ **
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29
0

**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.

0

To solve this problem.

  1. Step1: cd projectName
  2. Step2: npm update
  3. Step3: ng serve -o

For example : enter image description here

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
BehrouzMoslem
  • 9,053
  • 3
  • 27
  • 34