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

2019-01-30 21:12发布

问题:

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 !

I don't understand the problem

回答1:

Try to run

npm install

in the project folder



回答2:

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.



回答3:

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



回答4:

  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.



回答5:

from terminal

 > cd myProjectPath
 myProjectPath > npm install


回答6:

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.



回答7:

the fix for me was

npm link
ng build 



回答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.



回答9:

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



回答10:

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



回答11:

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



回答12:

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



回答13:

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!



回答14:

Below steps worked for me:

Delete node_modules folder and package-lock.json file. npm install ng serve



回答15:

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.



回答16:

After trying to no avail:

  • npm install
  • npm update
  • ng serve

npm install -g @angular/cli worked for me



回答17:

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



回答18:

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



回答19:

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



回答20:

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



回答21:

In my case the following worked:

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

Hence the npm install, not update.



回答22:

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



回答23:

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.



回答24:

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.



回答25:

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



回答26:

To solve this problem.

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

For example :



回答27:

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