ffmpeg.wasm icon indicating copy to clipboard operation
ffmpeg.wasm copied to clipboard

Node >16 `TypeError`: Failed to parse URL from @ffmpeg/core/dist/ffmpeg-core.wasm

Open usr-ein opened this issue 2 years ago • 2 comments

Describe the bug When running the first example on the README in a NodeJS environment, I get the following error:

❯ node --experimental-wasm-threads index.js
[info] use ffmpeg.wasm v0.11.4
[info] load ffmpeg-core
[info] loading ffmpeg-core

[fferr] TypeError: Failed to parse URL from /path/to/nodeFfmpeg/node_modules/@ffmpeg/core/dist/ffmpeg-core.wasm
/path/to/nodeFfmpeg/node_modules/@ffmpeg/core/dist/ffmpeg-core.js:12

if(l){ra=oa?require("path").dirname(ra)+"/":__dirname+"/";ta=function(a,b){wa||(wa=require("fs"));xa||(xa=require("path"));a=xa.normalize(a);return wa.readFileSync(a,b?null:"utf8")};va=function(a){a=ta(a,!0);a.buffer||(a=new Uint8Array(a));assert(a.buffer);return a};1<process.argv.length&&(ka=process.argv[1].replace(/\\/g,"/"));ja=process.argv.slice(2);process.on("uncaughtException",function(a){if(!(a instanceof ca))throw a;});process.on("unhandledRejection",u);la=function(a){process.exit(a)};f.inspect=
                                                                                                                           
                                                                                                                                                                                                                                                                                                         ^

RuntimeError: abort(TypeError: Failed to parse URL from /path/to/nodeFfmpeg/node_modules/@ffmpeg/core/dist/ffmpeg-core.wasm). Build with -s ASSERTIONS=1 for more info.
    at process.u (/path/to/nodeFfmpeg/node_modules/@ffmpeg/core/dist/ffmpeg-core.js:25:109

To Reproduce Steps to reproduce the behavior:

  1. Download the attach ZIP containing package.json, package-lock.json, index.js and the flame test.avi ==> node-ffmpeg-error.zip
  2. npm install everything
  3. node --experimental-wasm-threads index.js
  4. See error

Expected behavior It's the default example, it should just run.

Desktop:

  • OS: Darwin Kernel Version 21.6.0 arm64

NodeJS:

  • Version v18.8.0

ffmpeg.wasm

  • @ffmpeg/core version: 0.11.0 (latest release rn)
  • @ffmpeg/ffmpeg version: 0.11.4 (latest release rn)

Additional context I wrote a lib that uses ffmpeg.wasm, and it works amazingly in the browser, but when running it on Node, despite my best efforts, I keep running into this.

I thought my setup was wrong so I created this minimalist NodeJS app that uses the README code, and lo and behold it shows the same error.

Here is the README code I'm referring to:

const fs = require('fs');
const { createFFmpeg, fetchFile } = require('@ffmpeg/ffmpeg');

const ffmpeg = createFFmpeg({ log: true });

(async () => {
  await ffmpeg.load();
  ffmpeg.FS('writeFile', 'test.avi', await fetchFile('./test.avi'));
  await ffmpeg.run('-i', 'test.avi', 'test.mp4');
  await fs.promises.writeFile('./test.mp4', ffmpeg.FS('readFile', 'test.mp4'));
  process.exit(0);
})();

usr-ein avatar Sep 06 '22 16:09 usr-ein

Downgrade node.js to v16 should work, not sure why node.js v18 doesn't work at the moment.

jeromewu avatar Sep 07 '22 02:09 jeromewu

Downgrade node.js to v16 should work, not sure why node.js v18 doesn't work at the moment.

Downgrading to Node.js v16.17.0 fixed it! I added the following to my package.json to be sure:

  "engines": {
    "node": "<=16.17.0"
  },

usr-ein avatar Sep 12 '22 14:09 usr-ein

I think this is still happening on newer node versions, its saying that fetch failed. It seems like this is the new error:

[fferr] TypeError: fetch failed
node_modules/@ffmpeg/ffmpeg/src/createFFmpeg.js:43
Uncaught RuntimeError RuntimeError: abort(TypeError: fetch failed). Build with -s ASSERTIONS=1 for more info.

aka I think it's having a problem grabbing the WASM file

Nukiloco avatar Oct 08 '22 15:10 Nukiloco

Was stuck on this for hours. Downgrading from Node 19 to 16 worked for me. Geez.

shn-dev-1 avatar Nov 27 '22 19:11 shn-dev-1

Still no updates?

maxpain avatar Mar 07 '23 20:03 maxpain

Downgrade to node 16.x still not work when deployed to Vercel.

Runetime: Node.js 16.x

[info] use ffmpeg.wasm v0.11.6
[info] load ffmpeg-core
[info] loading ffmpeg-core
Error: Cannot find module '@ffmpeg/core'
Require stack:
- /var/task/node_modules/@ffmpeg/ffmpeg/src/node/getCreateFFmpegCore.js
- /var/task/node_modules/@ffmpeg/ffmpeg/src/node/index.js
- /var/task/node_modules/@ffmpeg/ffmpeg/src/createFFmpeg.js
- /var/task/node_modules/@ffmpeg/ffmpeg/src/index.js
- /var/task/.next/server/pages/api/whisper.js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/___next_launcher.cjs

chengsokdara avatar Mar 09 '23 12:03 chengsokdara