You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase9.0.1执行yarn install报Package路径未导出错误怎么解决

问题根因

Firebase v9 重构为完全模块化的SDK,官方移除了package.json中根路径"./"的默认导出配置,旧版的全量导入写法、webpack默认的模块解析规则不匹配新的导出规则就会触发该报错。

解决方案

  • 修正Firebase导入语法
    弃用旧的全量导入写法:
    // 错误写法,v9已不支持
    import firebase from 'firebase'
    
    改为按需导入对应的子模块:
    // 正确的v9模块化写法
    import { initializeApp } from 'firebase/app'
    import { getAuth } from 'firebase/auth'
    import { getFirestore } from 'firebase/firestore'
    
    如需兼容v8版本的链式调用写法,可以使用兼容包:
    // 兼容v8写法的导入方式
    import firebase from 'firebase/compat/app'
    import 'firebase/compat/auth'
    import 'firebase/compat/firestore'
    
  • 调整ERB模板的webpack配置
    找到ERB模板下的.erb/configs/webpack.config.base.js文件,在resolve配置项中添加exportsFields规则,确保webpack适配新的package导出规范:
    module.exports = {
      // 其他原有配置
      resolve: {
        exportsFields: ['exports', 'main', 'module'],
        // 其他原有resolve配置
      }
    }
    
  • 重置依赖缓存
    执行以下命令清除旧的缓存和依赖后重新安装:
    rm -rf node_modules yarn.lock
    yarn cache clean
    yarn install
    

内容的提问来源于stack exchange,提问作者Kiran Maniya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 02:36:05