问题描述
升级到8.0.0后,出现以下错误:
After upgrading to 8.0.0, I get the following error:
我的导入看起来像这样:
My import looks like this:
import * as firebase from "firebase/app"
firebase.initializeApp({ ... })
TypeScript也抱怨:
TypeScript also complains:
我该如何解决?
推荐答案
在版本 8.0.0 ,Firebase SDK在处理导出方式方面发生了重大变化:
In version 8.0.0, the Firebase SDK had a breaking change in the way it handles exports:
8.0.0之前
import * as firebase from 'firebase/app'
8.0.0之后
import firebase from 'firebase/app'
使用 require('firebase/app')
或 require('firebase')
的代码将仍然可以使用,但是为了获得正确的输入(用于代码完成,例如)用户应将这些要求更改为 require('firebase/app').default
或 require('firebase').default
.这是因为SDK现在使用ESM捆绑软件的类型,而不同的捆绑软件共享一个打字文件.
Code that uses require('firebase/app')
or require('firebase')
willstill work, but in order to get proper typings (for code completion,for example) users should change these require calls torequire('firebase/app').default
or require('firebase').default
. Thisis because the SDK now uses typings for the ESM bundle, and thedifferent bundles share one typings file.
因此,您将必须使用新的ESM捆绑包默认导出:
So, you will have to use the new ESM bundle default export:
import firebase from "firebase/app"
firebase.initializeApp({ ... })
这篇关于升级到Firebase JS 8.0.0:尝试导入错误:未从"firebase/app"(导入为"firebase")导出"app"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!