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

Firebase Functions升级Node.js 18后ffmpeg启动失败(ENOENT)求助

解决Firebase Functions Node.js 18下spawn ffmpeg ENOENT的问题

问题原因

Node.js 18环境中,Firebase Functions的系统PATH配置和Node.js 16存在差异,直接调用ffmpeg命令无法定位到@ffmpeg-installer/ffmpeg安装的二进制文件,因此触发ENOENT错误。

解决步骤

  1. 保留现有依赖:@ffmpeg-installer/ffmpeg@^1.1.0本身兼容Node.js 18,无需替换,只需确保部署时依赖已正确安装。
  2. 使用绝对路径调用ffmpeg:不要直接用'ffmpeg'作为spawn的命令,而是通过安装包获取二进制文件的绝对路径。

修改后的代码示例

CommonJS格式:

const { spawn } = require('child_process');
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;

// 替换原spawn调用
await spawn(
  ffmpegPath,
  ['-i', 'input.mp4', 'output.mp4'], // 替换为你的实际参数数组
  { stdio: 'inherit' } // 可选,用于捕获ffmpeg输出日志,方便调试
);

ES模块格式(若使用import):

import { spawn } from 'child_process';
import ffmpeg from '@ffmpeg-installer/ffmpeg';

await spawn(
  ffmpeg.path,
  ['-i', 'input.mp4', 'output.mp4'],
  { stdio: 'inherit' }
);

额外检查

  • 部署前确认本地node_modules已正确安装,使用firebase deploy --only functions时,Firebase会自动处理依赖安装,无需手动上传node_modules。
  • 若临时调试遇到权限问题,可尝试在spawn选项中添加{ shell: true },但不推荐长期使用(存在安全风险),优先采用绝对路径方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 14:42:37