error TS2307: Cannot find module of exported reducer in barrel index file
See original GitHub issueAfter upgrading to Angular6, i am always getting Cannot find module ‘./src/app/default-strategy-plan-reducer’ while packaging
here is my default-strategy-plan-reducer file
import * as DefaultStrategyPlanChanged from '../utilities/actions';
export type Action = DefaultStrategyPlanChanged.All;
export interface DefaultStrategyPlan {
StrategyPlanID: string,
StrategyPlanNameEn: string
StrategyPlanNameAr: string
}
export type DefaultStrategyPlanState = DefaultStrategyPlan;
const initialState: DefaultStrategyPlanState = {
StrategyPlanID: ,
StrategyPlanNameEn: ,
StrategyPlanNameAr:
};
export function defaults (state = initialState, action: Action): DefaultStrategyPlanState {
switch (action.type) {
case "DefaultStrategyPlanChanged": {
return Object.assign({}, state, action.payload);
}
default: {
return state;
}
}
}
and actually i am importing all reducers in index file end exporting reducer containing all reducers in index.ts file which is in the same path level of reducers as follow:
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/let';
import { Observable } from 'rxjs/Observable';
import { compose, ActionReducerMap } from '@ngrx/store';
import { combineReducers, Store, Action } from '@ngrx/store';
import { GetTimeFiltersItems, defaults as selectedTimeFilter, SelectedTimeFilterState, TimeFilterItemsState } from './time-filter-reducer';
import { GetStrategyItems, defaults as selectedStrategItem, SelectedStrategyPlanFilterState, StrategyPlanItems } from './strategy-plan-filter-reducer';
import * as fromOrganizationUnitFilter from './organization-unit-filter-reducer';
import * as fromStructureFilter from './structure-node-filter-reducer';
import * as fromDefaultStrategyPlanReducer from './default-strategy-plan-reducer';
import * as fromOrganizationUnitsReducer from './organization-units-reducer';
import * as fromTimeFilterFrequenciesReducer from './time-filter-frequency-reducer';
import * as fromStructureFoldersReducer from './structure-folders-reducer';
import * as fromUpdateTrackingReducer from './update-tracking-reducer';
import * as fromQueryParameters from './query-parameters';
import * as StrategyItemMetadataReducer from './strategy-item-metadata-reducer';
import * as KPIManagementReducer from './kpi-management-reducer';
import * as MetricReducer from './metric-reducer';
import * as StrategyItemReducer from './strategy-item-reducer'
import * as OrganizationUnitsNamesReducer from './organization-units-names-reducer'
export interface AppState {
selectedTimeFilter: SelectedTimeFilterState,
timeFilterItems: TimeFilterItemsState,
selectedOrganizationUnit: fromOrganizationUnitFilter.SelectedOrganizationUnitFilterState,
selectedStructure: fromStructureFilter.SelectedStructureFilterState,
SelectedStrategyPlanFilter: SelectedStrategyPlanFilterState,
DefaultStrategyPlan: fromDefaultStrategyPlanReducer.DefaultStrategyPlanState,
organizationUnits: fromOrganizationUnitsReducer.OrganizationUnitsState,
strategyPlans: StrategyPlanItems,
timeFilterFrequencies: fromTimeFilterFrequenciesReducer.TimeFilterFrequencyState,
structureFolders: fromStructureFoldersReducer.StructureFolders,
updateTracking: fromUpdateTrackingReducer.UpdateTracking,
queryParameters: fromQueryParameters.QueryParams,
StrategyItemMetadata: StrategyItemMetadataReducer.StrategyItemMetadata,
KPIManagement: KPIManagementReducer.KPIState,
MetricState: MetricReducer.MetricState,
OrganizationUnitsNames:any,
StrategyItem: any
}
export function getState(store: Store<AppState>): AppState {
let state: AppState;
store.take(1).subscribe(s => state = s);
return state;
}
export const reducers: ActionReducerMap<AppState> = {
selectedTimeFilter: selectedTimeFilter,
timeFilterItems: GetTimeFiltersItems,
selectedOrganizationUnit: fromOrganizationUnitFilter.defaults,
selectedStructure: fromStructureFilter.defaults,
SelectedStrategyPlanFilter: selectedStrategItem,
DefaultStrategyPlan: fromDefaultStrategyPlanReducer.defaults,
organizationUnits: fromOrganizationUnitsReducer.defaults,
strategyPlans: GetStrategyItems,
timeFilterFrequencies: fromTimeFilterFrequenciesReducer.defaults,
structureFolders: fromStructureFoldersReducer.defaults,
updateTracking: fromUpdateTrackingReducer.defaults,
queryParameters: fromQueryParameters.defaults,
StrategyItemMetadata: StrategyItemMetadataReducer.defaults,
KPIManagement: KPIManagementReducer.defaults,
MetricState: MetricReducer.defaults,
StrategyItem: StrategyItemReducer.defaults,
OrganizationUnitsNames: OrganizationUnitsNamesReducer.defaults
};
So briefly the problem is with two things: first the error is indicating that it is looking for a module while i am not exporting module from the reducer. And the second issue is that the path written while packaging is wrong Cannot find module ‘./src/app/default-strategy-plan-reducer’ while the actual path is src/app/reducer/default-strategy-plan-reducer although the paths is accurate in the main project and the main project is working file with webpack but the problem is with packaging
Angular version: 6.0.9
Angular CLI version: 6.0.8
ng-packagr version: 3.0.3
Typescript verion: 2.7.2
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top GitHub Comments
I have the same issue. Here is the output:
And my reducer index.ts (which is located in libs/shared/src/lib/reducers/):
It seems that the compiler does not have the correct path (it’s missing the /reducers/ in the path) when dealing with barrel. Indeed, if I rename the index.ts into something else (i.e.: root.ts), the error does not happen anymore. In my module file (located in libs/shared/src/lib/), the import was
import { reducers } from './reducers';
and after the renameimport { reducers } from './reducers/root';
.This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
This action has been performed automatically by a bot.