Why do i keep getting the NG0203 error when i build my Angular app using esbuild?

Discussão em 'Angular' iniciado por Jelle Schrans, Janeiro 31, 2025.

  1. Im trying to migrate to esbuild to build my Angular application. I've completed everything i needed to do, but i keep seeing this error being logged in the console:

    Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with runInInjectionContext

    I've tried everything thats described here, at 'Using application builder': https://angular.io/guide/esbuild

    My app.config.ts looks like this:

    export const appConfig: ApplicationConfig = {
    providers: [
    importProvidersFrom(
    BrowserModule,
    SharedModule,
    DataSetModule,
    LookUpTablesModule,
    NormsModule,
    StoreModule.forRoot({
    mappings: mappingsReducer,
    auth: authReducer,
    }),
    EffectsModule.forRoot([AuthEffects])
    ),
    provideAnimations(),
    provideHttpClient(),
    provideRouter(routes),
    ],
    };


    And i inject classes like this, which worked with the former builder:

    constructor(
    private router: Router,
    public excelDownload: ExcelDownloadService,
    private route: ActivatedRoute,
    private dataSetService: DataSetService
    ) {} ```

    Edit: this is the exact error that is being logged:
    `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 with `runInInjectionContext`. Find more at https://angular.io/errors/NG0203
    at injectInjectorOnly (core.mjs:985:15)
    at ɵɵinject3 (core.mjs:998:42)
    at Object.factory (core.mjs:27529:46)
    at core.mjs:6247:43
    at runInInjectorProfilerContext (core.mjs:948:9)
    at R3Injector.hydrate (core.mjs:6246:17)
    at R3Injector.get (core.mjs:6114:33)
    at definition.getStandaloneInjector (core.mjs:27545:31)
    at ComponentFactory.create (core.mjs:15477:57)
    at _ApplicationRef.bootstrap (core.mjs:31863:42)`

    Continue reading...

Compartilhe esta Página