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

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

问题描述

我有一个使用 CLI 1.5.4 升级到 Angular 5 的 Angular 4 应用程序.我还有一个使用 npm link 的共享库.升级后,我必须将其添加到我的 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.

推荐答案

我遇到了同样的问题.

首先,确保对您的模块所依赖的任何 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 了解更多详情.

See https://github.com/angular/angular-cli/issues/8677#issuecomment-347885068 for more details.

此外,这可能会有所帮助: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天全站免登陆