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:\workspace\Client\AngularApp\src\app\app.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
Without some background on your folder structure and configuration it's going to be hard but let's stick to the error
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'
This means that it can not find the file @lib/core-lib/lib/core-store/store/account/account.selector.ts which you intend to import
I suggest you first check the path is correct.
Besides that, there are a couple things I think you should double check:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With