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

Firebase第二代Node运行时云函数如何从同级文件导入ES6模块

解决Firebase Cloud Functions v2本地ES6导入报错问题

问题根源

你在package.json里加的"myfuncs": "file:./"本地纯属于画蛇添足,反而会干扰Firebase的代码分析工具。Firebase Cloud Functions处理本地同级文件导入,直接用相对路径就行,根本不需要额外声明本地依赖。

修复步骤

  • 删除多余依赖:打开functions目录下的package.json,删掉"myfuncs": "file:./"这一行,保存文件。
  • 确认导出语法正确:myfuncs.js必须用ES6的导出方式,不能用CommonJS语法,比如:
    // myfuncs.js
    export const myFunc = () => {
      // 你的函数逻辑
    };
    
  • 保留正确的导入语句:index.js里的导入写法没问题,也可以加上.js后缀让路径更明确:
    // index.js
    import { myFunc } from "./myfuncs.js";
    
  • 重新部署:运行部署命令:
    firebase deploy --only functions
    

额外排查点

如果还是报错,试试强制清理缓存重新部署:

firebase deploy --only functions --force

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 02:23:12