1

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"
  ],

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

NullInjectorError: No provider for InjectionToken LocaleId!

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.

4

2 回答 2

0

在您的测试文件中导入 LOCALE_ID 模块,然后导出为 GLOBAL_PROVIDER。

import { LOCALE_ID } from '@angular/core';


export const GLOBAL_PROVIDER = [
  { provide: LOCALE_ID, useValue: 'en'}
];
于 2020-04-27T11:28:00.470 回答
0

我遇到了同样的问题。

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

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

ng serve --preserve-symlinks

有关更多详细信息,请参阅https://github.com/angular/angular-cli/issues/8677#issuecomment-347885068

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

于 2017-12-22T18:04:49.930 回答