{"id":807,"hash":"ca8e092286015bd8908002d23b3f4c044df9eebb7d4eb3107eefd10f6a9661c6","pattern":"Why do i keep getting the NG0203 error when i build my Angular app using esbuild?","full_message":"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:\n\nError: 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 \n\nI've tried everything thats described here, at 'Using application builder': https://angular.io/guide/esbuild\n\nMy app.config.ts looks like this:\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    importProvidersFrom(\n      BrowserModule,\n      SharedModule,\n      DataSetModule,\n      LookUpTablesModule,\n      NormsModule,\n      StoreModule.forRoot({\n        mappings: mappingsReducer,\n        auth: authReducer,\n      }),\n      EffectsModule.forRoot([AuthEffects])\n    ),\n    provideAnimations(),\n    provideHttpClient(),\n    provideRouter(routes),\n  ],\n};\n\nAnd i inject classes like this, which worked with the former builder:\n\nconstructor(\n    private router: Router,\n    public excelDownload: ExcelDownloadService,\n    private route: ActivatedRoute,\n    private dataSetService: DataSetService\n  ) {} ```\n\nEdit: this is the exact error that is being logged:\n`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\n    at injectInjectorOnly (core.mjs:985:15)\n    at ɵɵinject3 (core.mjs:998:42)\n    at Object.factory (core.mjs:27529:46)\n    at core.mjs:6247:43\n    at runInInjectorProfilerContext (core.mjs:948:9)\n    at R3Injector.hydrate (core.mjs:6246:17)\n    at R3Injector.get (core.mjs:6114:33)\n    at definition.getStandaloneInjector (core.mjs:27545:31)\n    at ComponentFactory.create (core.mjs:15477:57)\n    at _ApplicationRef.bootstrap (core.mjs:31863:42)`","ecosystem":"npm","package_name":"angular","package_version":null,"solution":"If you see this error while SWITCHING to ESBUILD, you probably have a @angular path in your tsconfig.\n\nREMOVE this option now, and it will fix the issue.\n\n\"paths\": {\n      \"@angular/*\": [\"./node_modules/@angular/*\"], <--- DELETE THIS\n      ...\n}\n\nContext:\nThis path was likely added to workaround an Angular issue when developing with a locally-linked library. There would be two Ivy instances and this path would tell your app which node_modules to read from.\nAt least that's what one popular guide said, and it seemed to fix the issue.\n\nI don't believe this is an issue anymore with esbuild. At least I haven't run into it, so it should be okay to remove this path.","confidence":0.9,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/77833386/why-do-i-keep-getting-the-ng0203-error-when-i-build-my-angular-app-using-esbuild","votes":4,"created_at":"2026-04-19T04:51:44.614188+00:00","updated_at":"2026-04-19T04:51:44.614188+00:00"}