NullInjectorError:使用 ng-packagr 时没有 StateObservable 的提供者 [英] NullInjectorError: No provider for StateObservable when using ng-packagr

查看:29
本文介绍了NullInjectorError:使用 ng-packagr 时没有 StateObservable 的提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 ngrx/store 的 Angular 5 项目.该项目由一个应用程序和一个应用程序使用的共享库组成.直到今天,我们一直在为两个项目一起编译 TypeScript - 该库正在发布",其中仅包含 TypeScript 代码.

I have an Angular 5 project that uses ngrx/store. The project consists of an application and a shared library that the application uses. Up until today, we had been compiling the TypeScript for both projects together - the library was being "published" with just the TypeScript code.

今天,我让这个库与 ng-packagr 一起工作,并使用 yarn link 将它拉入应用程序,以便我可以运行本地代码.但是,当我尝试启动我的应用程序时,我在浏览器中收到此错误:

Today, I got this library working with ng-packagr and pulled it in to the application using yarn link, so that I could run the local code. However, when I try to start my app, I get this error in the browser:

<代码>未处理的承诺拒绝:StaticInjectorError(AppModule)[Store ->状态观察]:静态注入器错误(平台:核心)[存储 ->状态观察]:NullInjectorError: 没有 StateObservable 的提供者!;区域:<根>;任务: Promise.then ;值:错误:StaticInjectorError(AppModule)[Store ->状态观察]:静态注入器错误(平台:核心)[存储 ->状态观察]:NullInjectorError: 没有 StateObservable 的提供者!在 _NullInjector.get (core.js:1002)在 resolveToken (core.js:1300)在 tryResolveToken (core.js:1242)在 StaticInjector.get (core.js:1110)在 resolveToken (core.js:1300)在 tryResolveToken (core.js:1242)在 StaticInjector.get (core.js:1110)在 resolveNgModuleDep (core.js:10854)在 _createClass (core.js:10895)在 _createProviderInstance$1 (core.js:10865)

我不知道这是错误的来源.我唯一的线索是它提到了 AppModule.在我的 AppModule 中,我正在导入 @ngrx/store 并将 StoreModule.forRoot 导入到我的模块中.

I have no idea where this is error coming from. My only clue is that it mentions AppModule. In my AppModule, I am importing @ngrx/store and importing StoreModule.forRoot into my module.

推荐答案

以下是我解决此问题的方法:

Here is how I fixed the issue in my case:

我导入了以下内容:

import { Store } from '@ngrx/store';
import { StoreModule } from '@ngrx/store';

我在导入中添加了 store 模块: imports: [StoreModule.forRoot({}),............

I added the store module in imports as : imports: [StoreModule.forRoot({}),............

然后我将商店服务添加到提供者:providers: [Store]

Then I added the store service to the providers : providers: [Store]

关键是检查缺失的提供者.希望这会有所帮助!

Key point is to check missing providers. Hope this helps!

这篇关于NullInjectorError:使用 ng-packagr 时没有 StateObservable 的提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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