简体   繁体   English

如何将 firebase.auth 导入到 angular 10

[英]how to import firebase.auth to angular 10

I have been using firebase for several years, and how to import it properly has always been a mystery to me. firebase我用了好几年了,如何正确导入一直是个谜。 I have been doing this:我一直在这样做:

import { auth } from 'firebase/app';
const p = new auth.GoogleAuthProvider();
this._angularfireauth.signInWithRedirect(p);

After upgrade to Angular 10, I got warnings升级到 Angular 10 后,我收到警告

depends on firebase/app. CommonJS or AMD dependencies can cause optimization bailouts.

I suppose it means firebase/app is a commonJS module.我想这意味着 firebase/app 是一个 commonJS 模块。 What can I do with it?我能用它做什么? It seems that the alternative似乎替代品

import * as firebase from 'firebase/app';
const p = new firebase.auth.GoogleAuthProvider();
this._angularfireauth.signInWithRedirect(p);

is just as bad.一样糟糕。

What is the proper way to do this?这样做的正确方法是什么?

The npm package firebase itself is not an ECMAScript module and therefore produces the warning. npm package firebase本身不是 ECMAScript 模块,因此会产生警告。

If there is no ES modulized build available for your library, or if you for some reason don't care, you can add can allow specific CommonJS dependencies in the angular.json file:如果您的库没有可用的 ES 模块化构建,或者由于某种原因不关心,您可以在angular.json文件中添加可以允许特定的 CommonJS 依赖项:

"build": {
  "builder": "@angular-devkit/build-angular:browser",
  "options": {
    // ...
    "allowedCommonJsDependencies": ["firebase/app"]
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM