Angular 5 NullInjectorError:没有n的提供者 [英] Angular 5 NullInjectorError: No provider for n
问题描述
当我使用 ng服务
启动我的网站时,一切正常,但每次尝试启动生产都会收到错误 NullInjectorError:No provider对于n
。我检查了我写的所有服务都包含在NgModule提供程序中。因为这是生产,所有文件都被缩小和丑化,所以我不知道究竟是什么导致了问题。有没有办法检查它或者可能从错误详细信息中获取?
When I'm starting my website with ng serve
everything works fine, but every try to launch a production getting an error NullInjectorError: No provider for n
. I checked all services that I wrote are included in NgModule providers. Because this is the production, all files are minified and uglified, so I don't know what exactly cause the problem. Is there any way to check it or maybe it's possible to get from the error details?
ERROR Error: StaticInjectorError(G)[n -> n]:
StaticInjectorError(Platform: core)[n -> n]:
NullInjectorError: No provider for n!
at n.get (main.94f42881e2fdceca85d7.bundle.js:1)
at main.94f42881e2fdceca85d7.bundle.js:1
at n (main.94f42881e2fdceca85d7.bundle.js:1)
at n.get (main.94f42881e2fdceca85d7.bundle.js:1)
at main.94f42881e2fdceca85d7.bundle.js:1
at n (main.94f42881e2fdceca85d7.bundle.js:1)
at n.get (main.94f42881e2fdceca85d7.bundle.js:1)
at Pi (main.94f42881e2fdceca85d7.bundle.js:1)
at main.94f42881e2fdceca85d7.bundle.js:1
at Li (main.94f42881e2fdceca85d7.bundle.js:1)
推荐答案
这可能是由于 JIT
(即时)和 AOT
的差异(提前)编译器。请在文档中了解详情。
This is probably due to the differences of JIT
(just-in-time) and AOT
(ahead-of-time) compiler. Read more about this in the docs.
如果你运行 ng服务
或 ng build
它将使用 JIT
默认情况下。但是,使用 - prod
标志,使用 AOT
。
If you run ng serve
or ng build
it will use JIT
by default. With the --prod
flag however, AOT
is used.
尝试运行 ng serve --aot
或 ng serve --prod
以查看更易于理解的错误消息。由于这不再慢,我建议在开发过程中始终使用 - aot
标志。你会更早地看到问题。
Try running ng serve --aot
or ng serve --prod
to see a more comprehensible error message. Since this is not much slower any more, I'd recommend always using the --aot
flag during development. You will see problems much earlier.
这篇关于Angular 5 NullInjectorError:没有n的提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!