Angular 5升级NullInjectorError:没有用于InjectionToken LocaleId的提供程序 [英] Angular 5 Upgrade NullInjectorError: No provider for InjectionToken LocaleId

查看:113
本文介绍了Angular 5升级NullInjectorError:没有用于InjectionToken LocaleId的提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Angular 4应用程序,已使用CLI 1.5.4升级到Angular 5.我也有一个使用npm链接的共享库.升级后,我必须将其添加到tsconfig.app.json中才能重新构建CLI:

I have an Angular 4 app that I have upgraded to Angular 5 with CLI 1.5.4. I also have a shared library using npm link. After upgrading I had to add this to my tsconfig.app.json to get the CLI building again:

  "include": [
    "./**/*.ts",
    "../node_modules/my-lib/src/**/*.ts",
    "../node_modules/my-lib/index.ts",
    "../node_modules/my-lib/ng2-icad-cf.ts"
  ],

构建成功后,访问localhost:4200时出现以下错误

After a successful build, I am presented with the following error when visiting localhost:4200

NullInjectorError: No provider for InjectionToken LocaleId!

我在项目中找不到对LOCALE/LocaleId的任何引用.我怀疑链接库可能是个问题,因为我对Http具有相同的NullIjectorError(库使用Http,项目使用HttpClient),但此后在将HttpClient添加到库的主模块中后消失了,即使是还原并删除它之后也是如此...很奇怪.

I could not find any references to LOCALE / LocaleId in my project. I suspect the linked library might be the issue as I had the same NullIjectorError for Http (library uses Http, project uses HttpClient) but it has since disappeared after adding HttpClient to the library's main module, even after reverting back and removing it... very strange.

推荐答案

我遇到了同样的问题.

I experienced the same issue.

首先,请确保对模块所依赖的任何Angular库使用"peerDependencies",如下所述: https://github.com/angular/angular-cli/issues/3854#issuecomment-274344771

First, make sure to use "peerDependencies" for any Angular libraries that your module depends on as described here: https://github.com/angular/angular-cli/issues/3854#issuecomment-274344771

然后尝试通过将--preserve-symlinks传递给Angular CLI来运行/构建应用程序.例如:

Then try running / building the app by passing --preserve-symlinks to Angular CLI. For example:

ng serve --preserve-symlinks

请参见 https://github.com/angular/angular- cli/issues/8677#issuecomment-347885068 了解更多详情.

此外,这可能会有所帮助: https://github.com/angular/angular-cli/wiki/stories-linked-library

Also, this may help: https://github.com/angular/angular-cli/wiki/stories-linked-library

这篇关于Angular 5升级NullInjectorError:没有用于InjectionToken LocaleId的提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆