我在Angular 6应用程序中使用Firebase,并且在使用如下所示的导入时,
import { auth, User } from 'firebase';
我在浏览器控制台中收到此警告:
It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.
For the module builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):
CommonJS Modules:
const firebase = require('firebase/app');
require('firebase/<PACKAGE>');
ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';
每当我将导入内容切换为import * as auth from 'firebase/auth'
之类的时候:
export 'GoogleAuthProvider' (imported as 'auth') was not found in 'firebase/auth'
(因为我也在使用GoogleAuthProvider
)auth
变量不再具有其定义,我无法CTRL-CLICK看看发生了什么。答案 0 :(得分:2)
根据 danfri86 对此GitHub问题-https://github.com/firebase/angularfire/issues/968的评论-您应执行以下操作:
import firebase from 'firebase/app';
import 'firebase/auth'; // This line is important
export const googleProvider = new firebase.auth.GoogleAuthProvider();
这实际上是警告要执行的操作:
ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';
我刚刚测试了它,它没有引发任何错误。