角度服务并不起作用

时间:2018-01-19 01:49:28

标签: angular

每次我运行服务它都会给我:

module.js:540
    throw err;
    ^

Error: Cannot find module '@angular-devkit/core'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Lenovo\Desktop\Projects\ng\node_modules\@angular-devkit\schematics\src\tree\virtual.js:10:16)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)

我安装了nodejs稳定版本卸载nodejs安装另一次,但似乎没有什么工作

3 个答案:

答案 0 :(得分:2)

不是 ng server

它是

<强> ng serve

另外,请手动尝试以下操作

<强> npm install @angular-devkit/core --save

答案 1 :(得分:1)

您似乎忘记安装或保存到此package.json此软件包。跑吧

npm i @angular-devkit/core --save

“Angular ng server无法正常工作”

运行Angular的实际命令是ng serve,而不是ng server

答案 2 :(得分:0)

您的package.json必须如下所示:

"dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  }

如果你创建了一个新的proyect,你将安装这些软件包的最新主要版本(第一个数字)(例如@ angular / animations @ 5.1.3到@ angular / animations @ 5.2.1)。在您创建新项目时,似乎某些依赖项会更新。就我而言,这项工作(来自旧项目):

+-- @angular/animations@5.1.3
| `-- tslib@1.8.1
+-- @angular/common@5.1.3
| `-- tslib@1.8.1 deduped
+-- @angular/compiler@5.1.3
| `-- tslib@1.8.1 deduped
+-- @angular/core@5.1.3
| `-- tslib@1.8.1 deduped
+-- @angular/forms@5.1.3

| `-- tslib@1.8.1 deduped
+-- @angular/http@5.1.3
| `-- tslib@1.8.1 deduped
+-- @angular/platform-browser@5.1.3
| `-- tslib@1.8.1 deduped
+-- @angular/platform-browser-dynamic@5.1.3
| `-- tslib@1.8.1 deduped
+-- @angular/router@5.1.3
| `-- tslib@1.8.1 deduped
+-- bootstrap@4.0.0-beta.2
+-- core-js@2.5.3
+-- jquery@3.2.1
+-- popper.js@1.12.9
+-- rxjs@5.5.6
| `-- symbol-observable@1.0.1
`-- zone.js@0.8.19

而不是这个(新项目):

+-- @angular/animations@5.2.1
| `-- tslib@1.9.0
+-- @angular/common@5.2.1
| `-- tslib@1.9.0 deduped
+-- @angular/compiler@5.2.1
| `-- tslib@1.9.0 deduped
+-- @angular/core@5.2.1
| `-- tslib@1.9.0 deduped
+-- @angular/forms@5.2.1

| `-- tslib@1.9.0 deduped
+-- @angular/http@5.2.1
| `-- tslib@1.9.0 deduped
+-- @angular/platform-browser@5.2.1
| `-- tslib@1.9.0 deduped
+-- @angular/platform-browser-dynamic@5.2.1
| `-- tslib@1.9.0 deduped
+-- @angular/router@5.2.1
| `-- tslib@1.9.0 deduped
+-- core-js@2.5.3
+-- rxjs@5.5.6
| `-- symbol-observable@1.0.1
`-- zone.js@0.8.20

我解决了将angular cli更新为最新版本(https://github.com/angular/angular-cli#updating-angular-cli)并执行操作的问题 如果你的npm版本是&lt; npm installnpm install --save 5.0.0。 这将更新package.json和node_modules中的dev依赖项。