fluent-ffmpeg/node-fluent-ffmpeg

ReferenceError: `__dirname` is not defined

Stadly opened this issue · 0 comments

I cannot use fluent-ffmpeg in the production build of my SvelteKit app. It works in dev mode, and also in preview mode, but in the final production build, any call to ffmpeg results in a ReferenceError: __dirname is not defined. I guess it is an issue with ESM vs CommonJS.

Version information

  • fluent-ffmpeg version: 2.1.3
  • ffmpeg version: 5.1.5
  • OS: Alpine Linux (Windows Subsystem for Linux)

Code to reproduce

import ffmpeg from "fluent-ffmpeg";
ffmpeg();

(note: if the problem only happens with some inputs, include a link to such an input file)

Expected results

No errors

Observed results

ReferenceError: __dirname is not defined
    at new FfmpegCommand (file:///app/build/server/chunks/index-D6fKiITG.js:5210:69)
    at FfmpegCommand (file:///app/build/server/chunks/index-D6fKiITG.js:5178:13)
    at file:///app/build/server/chunks/0-DGpjmR_G.js:15:8
    at file:///app/build/server/chunks/server-DbC9RgP-.js:13:32
    at load_server_data (file:///app/build/server/chunks/index-B8KRwtQw.js:1464:42)
    at file:///app/build/server/chunks/index-B8KRwtQw.js:2947:24

Checklist

  • I have read the FAQ
  • I tried the same with command line ffmpeg and it works correctly (hint: if the problem also happens this way, this is an ffmpeg problem and you're not reporting it to the right place)
  • I have included full stderr/stdout output from ffmpeg