I have an angular library with store implementation and this library is packaged as a NPM and used in different angular application.
I'm trying to use a ngrx store selector which was exported in the library in my different angular project and the application throws an error.
Module not found: Error: Can't resolve
'@lib/core-lib/lib/core-store/store/account/account.selector' in
'C:workspaceClientAngularAppsrcappapp.component'
Angular Library Implementation:
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
);
exported this selector from the 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 Usage
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 Library works fine without any issue and getting this piece of selector into my angular application is giving me error on compilation.
I tried to provide as much detail as possible and let me know if I need to add anything else.
Any answer on this is much appreciated
question from:
https://stackoverflow.com/questions/65903604/ngrx-store-selector-failing-on-app-import-from-custom-library 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…