gpt4 book ai didi

javascript - 升级到 Firebase JS 8.0.0 : Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase' )

转载 作者:行者123 更新时间:2023-12-03 06:50:09 25 4
gpt4 key购买 nike

升级到 8.0.0 后,出现以下错误:

Attempted import error: 'initializeApp' is not exported from 'firebase/app' (imported as 'firebase').


我的导入如下所示:
import * as firebase from "firebase/app"
firebase.initializeApp({ ... })
TypeScript 还提示:

Property 'initializeApp' does not exist on type 'typeof import("/path/to/my/file")'. ts(2339)


我该如何解决?

最佳答案

在版本 8.0.0 ,Firebase SDK 在处理导出的方式上发生了重大变化:

Breaking change: browser fields in package.json files now point to ESMbundles instead of CJS bundles. Users who are using ESM imports mustnow use the default import instead of a namespace import.

Before 8.0.0

import * as firebase from 'firebase/app'

After 8.0.0

import firebase from 'firebase/app'

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 捆绑包默认导出:
import firebase from "firebase/app"
firebase.initializeApp({ ... })
如果您正在使用 SDK version 9.0 ,改为阅读这个问题:
  • How do I fix a Firebase 9.0 import error? "Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase')."
  • 关于javascript - 升级到 Firebase JS 8.0.0 : Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64545862/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com