Home
Support Forums

Async Module Bundling Issues - @ffmpeg/core and @ffmpeg/ffmpeg

https://ffmpeg-issue.netlify.app

Super Simple Example Repo

I am trying to get this to work - relies on an invisible dependency – @ffmpeg/core that needs to be loaded

It does not appear to be bundled with the function no matter what I do - even when importing ffmpeg/core and using a url for the core: GitHub - ffmpegwasm/ffmpeg.wasm: FFmpeg for browser and node, powered by WebAssembly

This works fine in development because the module can be found but cannot be found when built and deployed

How can I make sure this module is bundled and built?

1:22:33 PM: 2021-10-18T20:22:33.708Z	undefined	INFO	[info] use ffmpeg.wasm v0.10.1
1:22:33 PM: ef10ed9b INFO   [info] load ffmpeg-core
1:22:33 PM: ef10ed9b INFO   [info] loading ffmpeg-core
1:22:33 PM: ef10ed9b INFO   [info] fetch ffmpeg.wasm-core script from @ffmpeg/core
1:22:33 PM: ef10ed9b INFO   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/functions/ffmpeg-background.js
- /var/task/ffmpeg-background.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at /var/task/node_modules/@ffmpeg/ffmpeg/src/node/getCreateFFmpegCore.js:6:31
    at new Promise (<anonymous>)
    at module.exports (/var/task/node_modules/@ffmpeg/ffmpeg/src/node/getCreateFFmpegCore.js:3:36)
    at Object.load (/var/task/node_modules/@ffmpeg/ffmpeg/src/createFFmpeg.js:63:17)
    at load (/var/task/functions/ffmpeg-background.js:49:16)
    at Runtime.handler (/var/task/functions/ffmpeg-background.js:34:11) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/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/functions/ffmpeg-background.js',
    '/var/task/ffmpeg-background.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
  ]
}
1:22:33 PM: ef10ed9b Duration: 9.90 ms	Memory Usage: 63 MB	Init Duration: 181.43 ms	

I tried including both @ffmpeg/ffmpeg and @ffmpeg/ffmpeg in the external modules, removing both of them and still no dice for whatever reason - I tried to use the include option in the toml file but I am not sure if I am doing that right.

Hey @dashreel :wave: !

We looked into your netlify.toml file and didn’t see @ffmpeg/core defined in external_node_modules. Could you try adding core to external_node_modules and let us know if that works?

Made the requested change

Have this error:

ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '@ffmpeg/ffmpeg'\nRequire stack:\n- /var/task/functions/ffmpeg-background.js\n- /var/task/ffmpeg-background.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","stack":["Runtime.ImportModuleError: Error: Cannot find module '@ffmpeg/ffmpeg'","Require stack:","- /var/task/functions/ffmpeg-background.js","- /var/task/ffmpeg-background.js","- /var/runtime/UserFunction.js","- /var/runtime/index.js","    at _loadUserApp (/var/runtime/UserFunction.js:100:13)","    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","    at Object.<anonymous> (/var/runtime/index.js:43:30)","    at Module._compile (internal/modules/cjs/loader.js:999:30)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)","    at Module.load (internal/modules/cjs/loader.js:863:32)","    at Function.Module._load (internal/modules/cjs/loader.js:708:14)","    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)","    at internal/main/run_main_module.js:17:47"]}

I have tried all permutations of excluding those modules in the toml file - they all result in one of the modules failing to be found/loaded.

Interesting. I’m not seeing this error. I just cloned your repo, deployed it and checked the URL of the function. I got this error:

6:02:29 PM: 2021-10-21T12:32:29.832Z	undefined	INFO	[info] use ffmpeg.wasm v0.10.1
6:02:29 PM: 8571d6dc INFO   [info] load ffmpeg-core
6:02:29 PM: 8571d6dc INFO   [info] loading ffmpeg-core
6:02:29 PM: 8571d6dc INFO   [info] fetch ffmpeg.wasm-core script from @ffmpeg/core
6:02:29 PM: 8571d6dc INFO   [fferr] requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag
6:02:29 PM: 8571d6dc INFO   (on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)
6:02:29 PM: 8571d6dc INFO   Error: bad memory
    at /var/task/node_modules/@ffmpeg/core/dist/ffmpeg-core.js:23:1
    at Object.load (/var/task/node_modules/@ffmpeg/ffmpeg/src/createFFmpeg.js:64:20)
    at async load (/var/task/functions/ffmpeg-background.js:49:3)
    at async Runtime.handler (/var/task/functions/ffmpeg-background.js:34:5)
6:02:29 PM: 8571d6dc Duration: 50.00 ms	Memory Usage: 64 MB	Init Duration: 205.20 ms

I’ve deployed via continuous deployment and the netlify-cli and I never get that error.

How would we solve the error that you got?

I’m not sure if that’s solvable. The error says it’s trying to make it run in a browser?

Can i use a different node version to run functions?

Yes, you get Node 10, 12 and 14:

https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

Ahhh that is the problem - can I get access to 15 or 16 or newer at all?

Unfortunately, that’s something that AWS controls, not us. Till AWS doesn’t add support for those versions, we can’t add them.

1 Like