Skip to content

add standalone support for ng add @angular/fire #3365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
robertIsaac opened this issue May 27, 2023 · 8 comments
Closed

add standalone support for ng add @angular/fire #3365

robertIsaac opened this issue May 27, 2023 · 8 comments
Assignees

Comments

@robertIsaac
Copy link
Contributor

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

@1GBattle
Copy link

1GBattle commented Jun 4, 2023

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

@robertIsaac
Copy link
Contributor Author

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

@DimitriTsikaridze
Copy link

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{}

@spock123
Copy link

spock123 commented Jun 9, 2023

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
      
    ]
};

@davideast davideast self-assigned this Jun 26, 2023
@sasidharansd
Copy link
Contributor

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.

@Yassinmoh
Copy link

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!

@robertIsaac
Copy link
Contributor Author

fixed by #3451

@robertIsaac
Copy link
Contributor Author

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()))],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants