2

在遵循本教程时。这是我得到的错误。唯一的区别是我声明了一个指令而不是组件,尽管它在本地开发中工作正常,但是当通过 npm 安装时,它会给出以下错误:

Error: StaticInjectorError(AppModule)[ApplicationRef -> NgZone]: 
  StaticInjectorError(Platform: core)[ApplicationRef -> NgZone]: 
    NullInjectorError: No provider for NgZone!
    at NullInjector.get (VM1509 core.umd.js:1063)
    at resolveToken (VM1509 core.umd.js:1316)
    at tryResolveToken (VM1509 core.umd.js:1266)
    at StaticInjector.get (VM1509 core.umd.js:1161)
    at resolveToken (VM1509 core.umd.js:1316)
    at tryResolveToken (VM1509 core.umd.js:1266)
    at StaticInjector.get (VM1509 core.umd.js:1161)
    at resolveNgModuleDep (VM1509 core.umd.js:9322)
    at _createClass (VM1509 core.umd.js:9367)
    at _createProviderInstance$1 (VM1509 core.umd.js:9339)
console.(anonymous function) @ preview-45b825bb367532ab5b87a.js:1
(anonymous) @ main.ts:26
ZoneDelegate.invoke @ zone.js:388
Zone.run @ zone.js:138
(anonymous) @ zone.js:872
ZoneDelegate.invokeTask @ zone.js:421
Zone.runTask @ zone.js:188
drainMicroTaskQueue @ zone.js:595
Promise.then (async)
scheduleMicroTask @ zone.js:578
ZoneDelegate.scheduleTask @ zone.js:410
Zone.scheduleTask @ zone.js:232
Zone.scheduleMicroTask @ zone.js:252
scheduleResolveOrReject @ zone.js:862
ZoneAwarePromise.then @ zone.js:962
PlatformRef.bootstrapModule @ application_ref.ts:275
execute @ main.ts:19
4

1 回答 1

1

我在 GitHub 问题https://github.com/angular/angular/issues/20101中找到了答案

如前所述,我必须将组件库的 package.json 中的 dependencies 参数更改为 peerDependencies。

在那个问题中提到了一个非常有用的博客,它也解决了我的其他问题,这里是博客的链接

// package.json
...
dependencies: {
  "@angular/common": "^2.4.10",
  ...
}

将改为:

// package.json
...
peerDependencies: {
  "@angular/common": "^2.4.10",
  ...
}
于 2018-05-13T20:56:56.543 回答