Angular 5 NullInjectorError:n 没有提供者 [英] Angular 5 NullInjectorError: No provider for n
问题描述
当我使用 ng serve
启动我的网站时,一切正常,但每次尝试启动产品时都会出现错误 NullInjectorError: No provider for 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
(just-in-time) 和 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 serve
或 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屋!