Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: __dirname is not defined #1283

Open
3 tasks done
Stadly opened this issue Jun 25, 2024 · 3 comments · May be fixed by #1319
Open
3 tasks done

ReferenceError: __dirname is not defined #1283

Stadly opened this issue Jun 25, 2024 · 3 comments · May be fixed by #1319

Comments

@Stadly
Copy link

Stadly commented Jun 25, 2024

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
@moraxh
Copy link

moraxh commented Mar 12, 2025

Did you found a solution for this issue?

@Stadly
Copy link
Author

Stadly commented Mar 13, 2025

I just defined if it is not defined:

global.__dirname = global.__dirname ?? "";
ffmpeg(bufferStream).ffprobe((error, data) => {
  // ...
});

Looking at the source code, setting presets to a non-empty string might also work:

ffmpeg(bufferStream, { presets: "dummy-path-to-prevent-use-of-__dirname" }).ffprobe((error, data) => {
  // ...
});

Stadly added a commit to Stadly/node-fluent-ffmpeg that referenced this issue Mar 13, 2025
@Stadly Stadly linked a pull request Mar 13, 2025 that will close this issue
@Stadly
Copy link
Author

Stadly commented Mar 13, 2025

I've created a PR to fix this: #1319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants