ngrx 商店选择器在从自定义库导入应用程序时失败

ngrx store selector failing on app import from custom library

我有一个带有存储实现的 angular 库,这个库被打包为一个 NPM 并在不同的 angular 应用程序中使用。

我正在尝试使用在我的不同 angular 项目的库中导出的 ngrx 存储选择器,但应用程序抛出错误。

Module not found: Error: Can't resolve '@lib/core-lib/lib/core-store/store/account/account.selector' in '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'

Angular应用使用情况

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 应用程序时出现编译错误。

我尽量提供了详细信息,如果我需要添加任何其他内容,请告诉我。

非常感谢对此的任何回答

如果不了解您的文件夹结构和配置,这将很难,但让我们坚持错误

Module not found: Error: Can't resolve '@lib/core-lib/lib/core-store/store/account/account.selector' in 'C:\workspace\Client\AngularApp\src\app\app.component'

这表示找不到您要导入的文件@lib/core-lib/lib/core-store/store/account/account.selector.ts

建议你先检查路径是否正确

除此之外,我认为您应该仔细检查几件事:

  • 如果你说这个库在 npm 包中,为什么要使用别名 @lib?
  • 如果您从 public_api.ts 导出这些功能,为什么还要进行深度导入?