You seem to not be depending on “@angular/core”. T

2019-01-30 20:33发布

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

27条回答
Emotional °昔
2楼-- · 2019-01-30 20:58
  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.

查看更多
Bombasti
3楼-- · 2019-01-30 20:58

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

查看更多
倾城 Initia
4楼-- · 2019-01-30 21:00

To solve this problem.

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

For example : enter image description here

查看更多
做个烂人
5楼-- · 2019-01-30 21:01

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

查看更多
男人必须洒脱
6楼-- · 2019-01-30 21:02

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

查看更多
Animai°情兽
7楼-- · 2019-01-30 21:03

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.

查看更多
登录 后发表回答