angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

add standalone support for ng add @angular/fire

Open robertIsaac opened this issue 1 year ago • 6 comments

Version info

Angular: 16.0.3

Firebase: N/A

AngularFire: 7.6.1

Other (e.g. Ionic/Cordova, Node, browser, operating system): node 18.16, windows

How to reproduce these conditions

Steps to set up and reproduce

ng new fire-esbuild-reprod --standalone
cd fire-esbuild-reprod
ng add @angular/fire

Debug output

Specified module path /src/app/app.module.ts does not exist

Expected behavior

the ng add to complete

Actual behavior

it throw an error

robertIsaac avatar May 27 '23 22:05 robertIsaac

I am having the same problem were you able to find a fix?

1GBattle avatar Jun 04 '23 16:06 1GBattle

I am having the same problem were you able to find a fix?

I'd suggest to create a new project without a standalone, add firebase to it, then copy the generated files to your standalone project

robertIsaac avatar Jun 07 '23 02:06 robertIsaac

I am having the same problem were you able to find a fix?

I'd suggest to create a new project without a standalone, add firebase to it, then copy the generated files to your standalone project

or just create app.module.ts file add class with ngmodule decorator and then run the command. it won't throw an error and you can simply copy what was generated inside module to main.ts without creating whole new app.

import {NgModule} from "@angular/core"

@NgModule({
providers: []
})
export class AnyName{}

DimitriTsikaridze avatar Jun 08 '23 06:06 DimitriTsikaridze

This is how I do it, I make a file with firebase configuration, which exports the "provide" functions, and this is then used in the app configuration:

# My firebase environment is saved in the Angular environment file
# @environment is just a typescript path alias
import { importProvidersFrom, EnvironmentProviders } from '@angular/core';
import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
import { getFirestore, provideFirestore } from '@angular/fire/firestore';
import { provideAuth, getAuth } from '@angular/fire/auth';
import { environment } from '@environment';

const firebaseProviders: EnvironmentProviders = importProvidersFrom([
    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideFirestore(() => getFirestore()),
    provideAuth(() => getAuth())
]);

export { firebaseProviders };

Then in app.config.ts:

import { ApplicationConfig, isDevMode } from '@angular/core';
import { firebaseProviders } from '@shared/firebase';
# ... other stuff

export const appConfig: ApplicationConfig = {
    providers: [
       # ... other providers
        firebaseProviders
      
    ]
};

spock123 avatar Jun 09 '23 12:06 spock123

We should try to add it somewhere in the docs page, since angular made the standalone component as a default way when creating a new component. This will make things easy for new devs who are relatively new to angular.

sasidharansd avatar Jan 16 '24 18:01 sasidharansd

I get this error I use Angular v17 and @angular/fire: ^17.0.0-next.0 ERROR NullInjectorError: R3InjectorError(Standalone[_SubmitPageComponent])[Firestore -> Firestore -> Firestore -> Firestore]: NullInjectorError: No provider for Firestore!

Yassinmoh avatar Jan 27 '24 14:01 Yassinmoh

fixed by https://github.com/angular/angularfire/pull/3451

robertIsaac avatar Feb 25 '24 21:02 robertIsaac

I get this error I use Angular v17 and @angular/fire: ^17.0.0-next.0 ERROR NullInjectorError: R3InjectorError(Standalone[_SubmitPageComponent])[Firestore -> Firestore -> Firestore -> Firestore]: NullInjectorError: No provider for Firestore!

I tried it now, it works fine for me here is the generated code in app.config.ts

    importProvidersFrom(
      provideFirebaseApp(() => initializeApp({
        'projectId': '...',
        'appId': '...',
        'storageBucket': '...',
        'apiKey': '...',
        'authDomain': '...',
        'messagingSenderId': '...',
      }))),
    importProvidersFrom(provideFirestore(() => getFirestore()))],

robertIsaac avatar Feb 25 '24 21:02 robertIsaac