ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
7.96k stars 1.95k forks source link

Ngrx dependency injection issue with esbuild/build-angular:application #4304

Closed thoussem closed 2 months ago

thoussem commented 2 months ago

Which @ngrx/* package(s) are the source of the bug?

effects

Minimal reproduction of the bug/regression with instructions

After upgrading from angular 16 to angular 17, change the angular builder to use the esbuild builder: @angular-devkit/build-angular:browser -> @angular-devkit/build-angular:application When i serve the app get this runtime error:

Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used withrunInInjectionContext. Find more at https://angular.io/errors/NG0203 at injectInjectorOnly (core.mjs:1093:15) at ɵɵinject2 (core.mjs:1106:42) at Object.FeatureEffects_Factory [as factory] (feature-effects.ts:15:28) at chunk-BKMMLQFQ.js?v=f9269614:1898:35 at runInInjectorProfilerContext (chunk-BKMMLQFQ.js?v=f9269614:523:5) at R3Injector.hydrate (chunk-BKMMLQFQ.js?v=f9269614:1897:11) at R3Injector.get (chunk-BKMMLQFQ.js?v=f9269614:1790:23) at injectInjectorOnly (chunk-BKMMLQFQ.js?v=f9269614:646:36) at ɵɵinject (chunk-BKMMLQFQ.js?v=f9269614:652:59) at inject (chunk-BKMMLQFQ.js?v=f9269614:661:10)

app.module.ts

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    StoreModule.forRoot(reducers, {
      metaReducers,
      runtimeChecks: {
        strictStateImmutability: false,
        strictActionImmutability: false
      }
    }),
    EffectsModule.forRoot([FeatureEffects])
  ],
  providers: [],
  bootstrap: [AppComponent],
  exports: []
})
export class AppModule {}

Stackblitz example: https://stackblitz.com/~/github.com/thoussem/ngrx17-esbuild-issue

Expected behavior

No runtime issue.

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

Ngrx: "@ngrx/effects": "17.2.0", "@ngrx/entity": "17.2.0", "@ngrx/router-store": "17.2.0", "@ngrx/store": "17.2.0", "@ngrx/store-devtools": "17.2.0"

Angular version: 17 Node: v18.19.0

Other information

No response

I would be willing to submit a PR to fix this issue

markostanimirovic commented 2 months ago

Hi @thoussem,

This issue is not related to NgRx but to your configuration. Remove the following line from tsconfig.json:

      "@angular/*": ["./node_modules/@angular/*"]

Screenshot 2024-04-17 235031

And the error will disappear.

markostanimirovic commented 2 months ago

If you have any other questions, feel free to join our Discord server.

thoussem commented 2 months ago

@markostanimirovic thks for your help.