@ngrx/store 生产构建错误:'Store' 的模板编译期间出错

@ngrx/store Error on production build : Error during template compile of 'Store'

错误:

ERROR in ../@ngrx/store/store.ts(10,2): Error during template compile of 'Store'
Could not resolve @angular/core relative to /home/teebo/Development/node_modules/@ngrx/store/store.d.ts..

我在 Angular v6 和@ngrx/store 6.1.0.

我正在从 ./reducers/ui/index.ts 导出一些减速器,例如

export const uiReducers = combineReducers({
  formFields: fromFormFieldsReducer.reducer,
  forms: fromFormReducers.reducer,
  formGroups: fromFormGroupReducer.reducer
});

然后在appState.reducers.ts中我有如下导出

import { ActionReducerMap } from '@ngrx/store';
import { uiReducers } from './reducers/ui';
import { UIState } from './models/ui.model';
import { InjectionToken } from '@angular/core';

export interface AppState {
  ui: UIState;
}

export const reducerToken = new 
 InjectionToken<ActionReducerMap<AppState>>('Reducers');

 export function getReducers() {
   return { ui: uiReducers };
 }

 export const reducerProvider = [
   { provide: reducerToken, useFactory: getReducers }
 ];

然后在我的 app.module.ts 我有以下内容

...
import { StoreModule, MetaReducer } from '@ngrx/store';
import { reducerToken, reducerProvider } from 
 './state_store/appState.reducers'; 
...
imports: [..., StoreModule.forRoot(reducerToken),...]
...
providers: [..., reducerProvider, ...]                             

但是运行下面的npm脚本

"build:ssr": "npm run build:client-and-server-bundles && npm run 
 webpack:server",

我收到错误

ERROR in ../@ngrx/store/store.ts(10,2): Error during template compile of 'Store'
Could not resolve @angular/core relative to /home/teebo/Development/node_modules/@ngrx/store/store.d.ts..

非常感谢对此问题的任何帮助,谢谢。 我已经关注 github 上的 do me 线程来跟踪这样的问题 one

因为在没有提供者的情况下使用 ActionReducerMap 进行操作给了我

ERROR in app/app.module.ts(64,25): Error during template compile of 
'AppModule'
 Function calls are not supported in decorators but 'combineReducers' 
 was called in 'appStateReducers'
 'appStateReducers' references 'uiReducers' at 
 app/state_store/appState.reducers.ts(9,67)
  'uiReducers' calls 'combineReducers' at 
app/state_store/reducers/ui/index.ts(8,27).

不要手动调用 combineReducers 函数。如前所述 here,您可以尝试将 actionReducerMap 用于您的减速器并将其传递给 StoreModule.forRoot(reducers)

请参阅此 以进行实施

我通过在 tsconfig.app.json 中指定 node_modules 的路径找到了问题的解决方案,--prod 的构建现在可以工作了。我在编译器选项

中所做的更改如下
"compilerOptions": {
  "baseUrl": ".",
  "paths": { "@angular/*": ["../node_modules/@angular/*"] },
 }