Inject() must be called from an injection context such as a constructor in AngularFirestoreDoc after upgrading to Angular v19
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 45/100
- Tipo de issue
- Bug
- Clareza
- Precisa de esclarecimento
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- angular, firebase, typescript
Direção de pesquisa
Comece com a chamada em auth.service.ts na linha 38 e rastreie-a através de AngularFirestore.doc até angular-fire-compat-firestore.mjs, usando o stack trace NG0203 como ponto de entrada. Compare as versões de dependências informadas do Angular v19 e do @angular/fire v19 e revise a discussão da issue em busca de uma reprodução ou resolução estabelecida. Está concluído quando o erro de contexto de injeção estiver explicado e uma correção de compatibilidade verificada ou um próximo passo confirmado por um maintainer tiver sido identificado.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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 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
at injectInjectorOnly (core.mjs:1104:11)
at ɵɵinject (core.mjs:1114:40)
at inject (core.mjs:1199:10)
at <instance_members_initializer> (angular-fire-compat-firestore.mjs:93:14)
at new AngularFirestoreDocument (angular-fire-compat-firestore.mjs:98:3)
at _AngularFirestore.doc (angular-fire-compat-firestore.mjs:621:12)
at auth.service.ts:38:14
at switchMap.js:16:17
at OperatorSubscriber2._this._next (OperatorSubscriber.js:14:9)
at Subscriber2.next (Subscriber.js:32:12)
However, my auth service at line 38:14 only has the following code:
.doc<User>(`users/${user.uid}`)
The whole constructor looks like this (it is a angular service class)
providedIn: 'root',
})
export class AuthService {
isLoggedIn$: Observable<boolean>;
/** User data of database */
user$: Observable<User | null | undefined>;
userRoles$: Observable<string[]>;
userId: string | undefined = undefined;
username: string | undefined = undefined;
constructor(
readonly firestore: AngularFirestore,
readonly fireAuth: AngularFireAuth,
readonly router: Router,
) {
this.user$ = this.fireAuth.authState.pipe(
switchMap((user) => {
if (user) {
this.userId = user.uid;
return this.firestore
.doc<User>(`users/${user.uid}`)
.valueChanges()
.pipe(
map((userData) => {
if (userData) {
this.username = userData.username; // Assign username
}
return userData;
}),
);
} else {
this.userId = undefined;
this.username = undefined;
return new Observable<User | null>((observer) => observer.next(null));
}
}),
);
But I dont really know, why it does not work anymore in angular 19.
My package dependencies:
"dependencies": {
"@angular/animations": "^19.1.5",
"@angular/cdk": "^19.1.3",
"@angular/common": "^19.1.5",
"@angular/compiler": "^19.1.5",
"@angular/core": "^19.1.5",
"@angular/fire": "^19.0.0",
"@angular/forms": "^19.1.5",
"@angular/material": "^19.1.3",
"@angular/platform-browser": "^19.1.5",
"@angular/platform-browser-dynamic": "^19.1.5",
"@angular/router": "^19.1.5",
"@fortawesome/angular-fontawesome": "^1.0.0",
"@fortawesome/free-brands-svg-icons": "^6.7.1",
"@fortawesome/free-regular-svg-icons": "^6.7.1",
"@fortawesome/free-solid-svg-icons": "^6.7.1",
"@ng-select/ng-select": "^14.2.2",
"@ngx-translate/core": "^15.0.0",
"@ngx-translate/http-loader": "^8.0.0",
"angular-build-info": "^2.0.1",
"canvas-confetti": "^1.9.3",
"flowbite": "^2.5.2",
"ng-recaptcha-2": "^15.0.2",
"ngx-editor": "^18.0.0",
"ngx-quill": "^27.0.0",
"quill": "^2.0.3",
"quill2-emoji": "^0.1.2",
"rxjs": "~7.8.0",
"tslib": "^2.8.1",
"tw-elements": "^2.0.0",
"zone.js": "^0.15.0"
},
I also tried to set "preserveSymlinks": false, in angular.json however, the issue still persists.
- Linguagem predominante
- TypeScript
- Estrelas
- 7.8k
- Forks
- 2.2k
- Merge médio
- 2d 21h
- PRs com merge (30d)
- 7
Preparar o ambiente
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de angular/angularfire
-
Canary builds are ordered by commit hash, not by time, and an all-digit hash loses its leading zeroAbertacomp: build/pipeline type: bug version: current (v17+)
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
angular/angularfire#3771 ·
Mantenedores costumam responder em até 1 dia
-
comp: schematics type: bug version: current (v17+)
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 76/100
angular/angularfire#3768 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Use `TransferState` to hand server-rendered Firestore data to the browser, instead of reading every document twiceTalvez já em andamento @armando-navarro assumiu há 25 dias. Abertacomp: firestore comp: ssr priority: P0 (critical) type: feature version: current (v17+)
angular/angularfire#3757 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Six `firebase` entry points have no `@angular/fire` equivalent, so their exports are unreachableTalvez já em andamento @armando-navarro assumiu há 25 dias. Abertacomp: core type: feature
angular/angularfire#3755 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
comp: auth comp: ssr comp: zones type: bug version: current (v17+)
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 76/100
angular/angularfire#3748 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de angular/angularfire
Issues semelhantes
-
ADD openalgoAbertatemplate
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 1 dia
-
factory-active factory-automatic task-bug-reproduction-success task-identify-harness-labels-done task-identify-issue-type-done
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 90/100
vercel/ai#21528 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
bug Needs: Triage :mag:
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
microsoft/fluentui-contrib#671 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
sveltejs/acorn-typescript#150 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100