Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度6-由于NGRX,生产构建失败_Javascript_Angular_Angular Material_Angular Cli_Ngrx - Fatal编程技术网

Javascript 角度6-由于NGRX,生产构建失败

Javascript 角度6-由于NGRX,生产构建失败,javascript,angular,angular-material,angular-cli,ngrx,Javascript,Angular,Angular Material,Angular Cli,Ngrx,我想使用以下命令生成并测试生产构建: ng build --prod --configuration=production ng serve --prod --configuration=production 文件生成正确,但在浏览器中打开站点时,出现以下错误: 未捕获错误:StaticInjectorError[n->t]: 静态注入错误(平台:核心)[n->t]: NullInjectorError:没有t的提供程序 我的生产配置如下所示: "production": {

我想使用以下命令生成并测试生产构建:

ng build --prod --configuration=production 
ng serve --prod --configuration=production
文件生成正确,但在浏览器中打开站点时,出现以下错误:

未捕获错误:StaticInjectorError[n->t]: 静态注入错误(平台:核心)[n->t]: NullInjectorError:没有t的提供程序

我的生产配置如下所示:

       "production": {
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": true,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": true,
          "buildOptimizer": true,
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ]
        },
我意识到问题在于在我的应用程序中使用ngrx。当我以某种方式删除连接到ngrx的所有内容时,应用程序将正常打开。 你知道我该修什么吗

下面我在我的应用程序中附上一些ngrx的例子

应用模块

export const metaReducers: MetaReducer<AppState>[] = !environment.production ? [storeFreeze] : [];

  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    HttpClientModule,
    StoreModule.forRoot(reducers, {metaReducers}),
    EffectsModule.forRoot([AuthEffects]),
  ],

让我说,在AppModule中,我导入了SharedModule,它导出MaterialModule,它导出MatSnackBarModule。所以一切看起来都很好…

这似乎是CLI中的一个错误,请查看相应的

作为解决方案,您可以尝试以下方法:

  • 更新至@angular/cli和@angular devkit的最新版本(更新其他@angular软件包可能不会有什么坏处)
  • 清除node_模块并重新安装

旁注:prod构建的行为有所不同,因为它在开发模式中使用AoT编译器(提前)而不是JIT编译器(及时)。由于AoT模式现在几乎和JIT一样快,我建议在开发过程中也使用它,所以如果出现问题,您会得到即时反馈。有关更多信息,请参见此说明。

此错误的意思是,您的app.module.ts中没有提供任何服务。您可以发布整个app.module.ts吗this@SmokeyDawson你有没有关于如何识别丢失的服务的提示?你是否正在运行测试/应用程序中是否有.spec文件?如果是这样,您需要确保您正在组件测试床中导入MaterialModule.configureTestingModule({..})。是的,测试正在通过
  userState: Observable<User.State>;

  constructor(private store: Store<AppState>) {}

  ngOnInit() {
    this.userState = this.store.select('user');
  }
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {AuthGuard} from './shared-module/services/auth.guard';
import {AppComponent} from './app.component';
import {HomeComponent} from './home/home.component';
import {AppRoutingModule} from './app-routing.module';
import {ErrorComponent} from './shared-module/components/error/error.component';
import {Globals} from './shared-module/services/globals';
import {UserService} from './user-module/services/user.service';
import {FacebookModule} from 'ngx-facebook';
import {AuthenticationService} from './user-module/services/authentiation.service';
import {RouteReuseStrategy} from '@angular/router';
import {CustomRouteReuseStrategy} from './router-strategy';
import {NotAllowedComponent} from './shared-module/components/not-allowed/not-allowed.component';
import {MetaReducer, Store, StoreModule} from '@ngrx/store';
import {EffectsModule} from '@ngrx/effects';
import {AppState, reducers} from './store/app.reducers';
import {AuthEffects} from './store/auth/auth.effects';
import {SharedModule} from './shared-module/shared.module';
import {UserModule} from './user-module/user.module';
import {VideoManagerService} from './video-module/services/video-manager.service';
import {HttpClientModule} from '@angular/common/http';
import {SpecialistChoiceEffect} from './store/specialist-choice/specialist-choice.effects';
import {SpecialistService} from './specialist-module/services/specialist-service';
import {environment} from '../environments/environment';
import {storeFreeze} from 'ngrx-store-freeze';

export const metaReducers: MetaReducer<AppState>[] = !environment.production ? [storeFreeze] : [];

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    NotAllowedComponent,
    ErrorComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    HttpClientModule,
    FacebookModule.forRoot(),
    AppRoutingModule,
    StoreModule.forRoot(reducers, {metaReducers}),
    EffectsModule.forRoot([AuthEffects, SpecialistChoiceEffect]),
    SharedModule,
    UserModule
  ],
  providers: [
    AuthGuard,
    Globals,
    VideoManagerService,
    UserService,
    AuthenticationService,
    SpecialistService,
    Store,
    {
      provide: RouteReuseStrategy,
      useClass: CustomRouteReuseStrategy
    }
  ],

  bootstrap: [AppComponent]
})

export class AppModule {
}
 constructor(private actions$: Actions,
          private router: Router,
          public infoBar: MatSnackBar) {
  }