【发布时间】:2021-01-30 18:56:23
【问题描述】:
我有一个带有商店实现的角度库,这个库被打包为 NPM 并用于不同的角度应用程序。
我正在尝试使用在我的不同 Angular 项目的库中导出的 ngrx 存储选择器,并且应用程序抛出错误。
找不到模块:错误:无法解决 '@lib/core-lib/lib/core-store/store/account/account.selector' 在 'C:\workspace\Client\AngularApp\src\app\app.component'
Angular 库实现:
import { createSelector } from '@ngrx/store';
import { ILibState } from '../../lib.state';
import { IAccountState } from './account.state';
const selectAccounts = (state: IAppState) => state.accounts;
export const selectSelectedAccount = createSelector(
selectAccounts,
(state: IAccountState) => state?.selectedAccount
);
从 public_api.ts 中导出了这个选择器
export * from './lib/core-store/store/account/account.selector'
// Also tried this
// export { selectSelectedAccount } from './lib/core-store/store/account/account.selector'
// Also tried the barrel approach
// export * from './lib/core-store/store/account/index'
AngularApp 用法
app.component.ts
import { ILibState } from '@lib/core-lib/lib/core-store/lib.state';
import { select, Store } from '@ngrx/store';
import { takeUntil } from 'rxjs/operators';
import { selectSelectedAccount } from '@lib/core-lib/lib/core-store/store/account/account.selector';
this._store
.pipe(select(selectSelectedAccount), takeUntil(this.destroy$))
.subscribe((res) => {
if (res && this.selectedAccountCode !== res) {
this.selectedAccountCode = res.account;
}
});
Angular 库可以正常工作,没有任何问题,将这块选择器放入我的 Angular 应用程序会导致编译出错。
我尝试提供尽可能多的细节,如果我需要添加任何其他内容,请告诉我。
非常感谢您对此的任何回答
【问题讨论】:
标签: angular ngrx ngrx-store angular-library ng-packagr