Jus*_*s10 5 import firebase typescript angular google-cloud-firestore
我正在构建一个 Angular 网络应用程序,我是这样导入的:
import * as firebase from 'firebase';
db = firebase.firestore();
Run Code Online (Sandbox Code Playgroud)
但最近我不断收到这个错误:
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):
Typescript:
import * as firebase from 'firebase/app';
import 'firebase/<PACKAGE>';
Run Code Online (Sandbox Code Playgroud)
所以,很自然地,我把它改成了这样:
import * as firebase from 'firebase/app';
import 'firebase/firestore';
db = firebase.firestore();
Run Code Online (Sandbox Code Playgroud)
但错误并没有消失。不明白怎么去掉?
背景
仅当您像第一个代码片段中那样加载所有 Firebase 模块时,才会触发该警告消息。最佳实践是仅使用裸导入,就像您将其更改为:
import * as firebase from 'firebase/app';
import 'firebase/firestore';
Run Code Online (Sandbox Code Playgroud)
这仅导入firestore
模块。
解决方案
在您更改的任何文件中搜索导入from 'firebase'
。即使是这样的代码import {firestore} from 'firebase';
也会触发警告消息。