Title: Inject() must be called from an injection context such as a constructor in AngularFirestoreDoc after upgrading to Angular v19 · Issue #3621 · angular/angularfire · GitHub
Open Graph Title: Inject() must be called from an injection context such as a constructor in AngularFirestoreDoc after upgrading to Angular v19 · Issue #3621 · angular/angularfire
X Title: Inject() must be called from an injection context such as a constructor in AngularFirestoreDoc after upgrading to Angular v19 · Issue #3621 · angular/angularfire
Description: I recently upgraded all dependencies to Angular v19 (from v18). I was previously on Angular v18 where everything worked fine. However, now, my whole console is spammed with the following error: ERROR RuntimeError: NG0203: inject() must b...
Open Graph Description: I recently upgraded all dependencies to Angular v19 (from v18). I was previously on Angular v18 where everything worked fine. However, now, my whole console is spammed with the following error: ERR...
X Description: I recently upgraded all dependencies to Angular v19 (from v18). I was previously on Angular v18 where everything worked fine. However, now, my whole console is spammed with the following error: ERR...
Opengraph URL: https://github.com/angular/angularfire/issues/3621
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inject() must be called from an injection context such as a constructor in AngularFirestoreDoc after upgrading to Angular v19","articleBody":"I recently upgraded all dependencies to Angular v19 (from v18). I was previously on Angular v18 where everything worked fine. However, now, my whole console is spammed with the following error:\n\n```\nERROR RuntimeError: 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.dev/errors/NG0203\n at injectInjectorOnly (core.mjs:1104:11)\n at ɵɵinject (core.mjs:1114:40)\n at inject (core.mjs:1199:10)\n at \u003cinstance_members_initializer> (angular-fire-compat-firestore.mjs:93:14)\n at new AngularFirestoreDocument (angular-fire-compat-firestore.mjs:98:3)\n at _AngularFirestore.doc (angular-fire-compat-firestore.mjs:621:12)\n at auth.service.ts:38:14\n at switchMap.js:16:17\n at OperatorSubscriber2._this._next (OperatorSubscriber.js:14:9)\n at Subscriber2.next (Subscriber.js:32:12)\n```\n\nHowever, my auth service at line 38:14 only has the following code:\n``.doc\u003cUser>(`users/${user.uid}`)``\n\nThe whole constructor looks like this (it is a angular service class)\n```@Injectable({\n providedIn: 'root',\n})\nexport class AuthService {\n isLoggedIn$: Observable\u003cboolean>;\n /** User data of database */\n user$: Observable\u003cUser | null | undefined>;\n userRoles$: Observable\u003cstring[]>;\n userId: string | undefined = undefined;\n username: string | undefined = undefined;\n\n constructor(\n readonly firestore: AngularFirestore,\n readonly fireAuth: AngularFireAuth,\n readonly router: Router,\n ) {\n this.user$ = this.fireAuth.authState.pipe(\n switchMap((user) => {\n if (user) {\n this.userId = user.uid;\n return this.firestore\n .doc\u003cUser>(`users/${user.uid}`)\n .valueChanges()\n .pipe(\n map((userData) => {\n if (userData) {\n this.username = userData.username; // Assign username\n }\n return userData;\n }),\n );\n } else {\n this.userId = undefined;\n this.username = undefined;\n return new Observable\u003cUser | null>((observer) => observer.next(null));\n }\n }),\n );\n```\n\nBut I dont really know, why it does not work anymore in angular 19.\n\nMy package dependencies:\n```\n \"dependencies\": {\n \"@angular/animations\": \"^19.1.5\",\n \"@angular/cdk\": \"^19.1.3\",\n \"@angular/common\": \"^19.1.5\",\n \"@angular/compiler\": \"^19.1.5\",\n \"@angular/core\": \"^19.1.5\",\n \"@angular/fire\": \"^19.0.0\",\n \"@angular/forms\": \"^19.1.5\",\n \"@angular/material\": \"^19.1.3\",\n \"@angular/platform-browser\": \"^19.1.5\",\n \"@angular/platform-browser-dynamic\": \"^19.1.5\",\n \"@angular/router\": \"^19.1.5\",\n \"@fortawesome/angular-fontawesome\": \"^1.0.0\",\n \"@fortawesome/free-brands-svg-icons\": \"^6.7.1\",\n \"@fortawesome/free-regular-svg-icons\": \"^6.7.1\",\n \"@fortawesome/free-solid-svg-icons\": \"^6.7.1\",\n \"@ng-select/ng-select\": \"^14.2.2\",\n \"@ngx-translate/core\": \"^15.0.0\",\n \"@ngx-translate/http-loader\": \"^8.0.0\",\n \"angular-build-info\": \"^2.0.1\",\n \"canvas-confetti\": \"^1.9.3\",\n \"flowbite\": \"^2.5.2\",\n \"ng-recaptcha-2\": \"^15.0.2\",\n \"ngx-editor\": \"^18.0.0\",\n \"ngx-quill\": \"^27.0.0\",\n \"quill\": \"^2.0.3\",\n \"quill2-emoji\": \"^0.1.2\",\n \"rxjs\": \"~7.8.0\",\n \"tslib\": \"^2.8.1\",\n \"tw-elements\": \"^2.0.0\",\n \"zone.js\": \"^0.15.0\"\n },\n```\n\nI also tried to set \"preserveSymlinks\": false, in angular.json however, the issue still persists.","author":{"url":"https://github.com/djamn","@type":"Person","name":"djamn"},"datePublished":"2025-02-12T15:14:12Z","url":"https://github.com/angular/angularfire/issues/3621"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c5d676bd-f419-9653-dce5-262a4e861cc3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E00:C727A:6D5790:8ABF87:6B0356DF |
| html-safe-nonce | 9c5b3c1e6ac0f81e01840c152d1a3d51f14c79b22d73959ae523a0a3595a1ba9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTAwOkM3MjdBOjZENTc5MDo4QUJGODc6NkIwMzU2REYiLCJ2aXNpdG9yX2lkIjoiMjc3NjAzMzY0MDkxMDY0MDg2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 49cef73f13e061216fcc21e8a4d757997df2c66be5047954e73aa363a616be9d |
| hovercard-subject-tag | issue:2848559540 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angularfire/3621/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f069e0f1963c6974772ccf2e803cd61e87bc28440a47b7ee890d8105445a1360/angular/angularfire/issues/3621 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f069e0f1963c6974772ccf2e803cd61e87bc28440a47b7ee890d8105445a1360/angular/angularfire/issues/3621 |
| og:image:alt | I recently upgraded all dependencies to Angular v19 (from v18). I was previously on Angular v18 where everything worked fine. However, now, my whole console is spammed with the following error: ERR... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | djamn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angularfire git https://github.com/angular/angularfire.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 49453413 |
| octolytics-dimension-repository_nwo | angular/angularfire |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49453413 |
| octolytics-dimension-repository_network_root_nwo | angular/angularfire |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width