[英]Angular2 "No provider for t!" and Uncaught (in promise): Error: DI Error
I've build a app in Angular 2, and have encountered a issue.我已经在 Angular 2 中构建了一个应用程序,但遇到了一个问题。 I have used angular CLI to create my application, I have created my components and services using Angular CLI and I use " ng serve " to run the application locally and everything works fine.
我使用 angular CLI 创建我的应用程序,我使用 Angular CLI 创建了我的组件和服务,我使用“ ng serve ”在本地运行应用程序,一切正常。 In order to create a build for PROD I'm using the command " ng build --Prod --base-href ./ --aot ", it creates a DIST folder and hosting the folder in IIS opens the application fine.
为了为 PROD 创建构建,我使用命令“ ng build --Prod --base-href ./ --aot ”,它创建了一个 DIST 文件夹,并在 IIS 中托管该文件夹可以很好地打开应用程序。 When I check in the code to TFS there is a event which automatically creates DIST folder using jenkins and pushes the build to my server.
当我将代码签入 TFS 时,有一个事件会使用 jenkins 自动创建 DIST 文件夹并将构建推送到我的服务器。 Now if I browse the application for server it throws the following errors " No provider for t! " and Error: DI Error.
现在,如果我浏览服务器的应用程序,它会抛出以下错误“ No provider for t! ”和错误:DI 错误。 I don't know what I'm doing wrong here.
我不知道我在这里做错了什么。
Below are the screenshots of the error下面是错误截图
Any help is much appreciated.任何帮助深表感谢。
I was having the same problem.我遇到了同样的问题。 I was able to solve it by:
我能够通过以下方式解决它:
ng serve -aot
.ng serve -aot
。 I was able to find out what the missing class was as this is running AOT without running minify/uglify. In my case, I was having a problem using the Logger class in the angular2-logger/core module.就我而言,我在使用 angular2-logger/core 模块中的 Logger 类时遇到了问题。 Once I removed the reference from the constructor and reran compilation, it worked like a charm.
一旦我从构造函数中删除了引用并重新编译,它就像一个魅力。 I then tested with
ng serve -prod
to confirm that was also fixed.然后我用
ng serve -prod
进行了测试以确认它也被修复了。
One thing I found was that I had to explicitly kill Angular CLI and rebuild.我发现的一件事是我必须明确杀死 Angular CLI 并重建。 For some reason, when I modified one line and saved, it said it recompiled and was still broken.
不知什么原因,我修改一行并保存时,它说它重新编译并仍然损坏。 Only when I killed it and ran the command again did I figure out it was really fixed.
只有当我杀死它并再次运行命令时,我才发现它真的修复了。
I had the same problem and the cause turned out to be a quirk in the angular2-logger library.我遇到了同样的问题,结果证明是 angular2-logger 库中的一个怪癖。 This answer solved the problem for me
这个答案为我解决了问题
fixed !固定的 ! in my case it was because the NotificationService for the angular2-notifications
就我而言,这是因为angular2-notifications的NotificationService
the solution is just remove the NotificationService from the providers array inside you app module .解决方案只是从app 模块内的 providers 数组中删除NotificationService 。
but still this is should be validated earlier by angular in AOT mode .但这仍然应该在 AOT 模式下通过 angular 提前验证。
Thanks!谢谢!
Here's one way to pinpoint the error - start by disabling the uglify plugin (which is automatically set for production) - and there's no way to do this with angular-cli.这是查明错误的一种方法- 首先禁用 uglify 插件(自动设置用于生产) - 而 angular-cli 无法做到这一点。 It can be temporarily commented out by searching for UglifyJSPlugin in node_modules directory.
可以通过在 node_modules 目录中搜索 UglifyJSPlugin 暂时注释掉。 After finding it (in the common.js file), comment it out
找到后(在common.js文件中),注释掉
/*
// Temporarily comment out this part (in common.js of node_modules) to pinpoint the error
new UglifyJSPlugin({
sourceMap: buildOptions.sourceMap,
parallel: true,
cache: true,
uglifyOptions,
}),
*/
Build your app again and run.再次构建您的应用程序并运行。 Then, a cryptic as heck error like this one
然后,像这样一个神秘的错误
Unhandled Promise rejection: StaticInjectorError(ne)[t -> t]:
StaticInjectorError(Platform: core)[t -> t]:
NullInjectorError: No provider for t! ; Zone: <root> ; Task: Promise.then ; Value: Error: StaticInjectorError(ne)[t -> t]:
StaticInjectorError(Platform: core)[t -> t]:
NullInjectorError: No provider for t!
becomes变成
Unhandled Promise rejection: StaticInjectorError(AppModule)[TranslatorService -> Http]:
StaticInjectorError(Platform: core)[TranslatorService -> Http]:
NullInjectorError: No provider for Http! ; Zone: <root> ; Task: Promise.then ; Value: Error: StaticInjectorError(AppModule)[TranslatorService -> Http]:
StaticInjectorError(Platform: core)[TranslatorService -> Http]:
NullInjectorError: No provider for Http!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.