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条回答
▲ chillily
2楼-- · 2019-01-30 21:10

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/ **
查看更多
甜甜的少女心
3楼-- · 2019-01-30 21:11

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.

查看更多
4楼-- · 2019-01-30 21:12

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

查看更多
Bombasti
5楼-- · 2019-01-30 21:12

In my case the following worked:

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

Hence the npm install, not update.

查看更多
时光不老,我们不散
6楼-- · 2019-01-30 21:13

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

查看更多
太酷不给撩
7楼-- · 2019-01-30 21:13

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.

查看更多
登录 后发表回答