question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught ReferenceError: createFFmpegCore is not defined

See original GitHub issue

As you can see the

import React from "react";
import { createFFmpeg, fetchFile } from "@ffmpeg/ffmpeg";

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

function App() {
  const [ready, setReady] = React.useState(false);

  const load = async () => {
    await ffmpeg.load();
    setReady(true);
  };

  React.useEffect(() => {
    load();
  }, []);

.
.
.

I got a Bad memory error too! How to fix this?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:21
  • Comments:21

github_iconTop GitHub Comments

9reactions
discretegamescommented, Jan 13, 2022

I found a fix! You have to go to node_modules/@ffmpeg/core/dist/ and copy all the files from there and paste them in the root folder, preferrably in the public folder if you’re using NextJS. Then use:

const ffmpeg = createFFmpeg({
  corePath: "http://localhost:3000/public/ffmpeg-core.js",
  // Use public address
  log: true,
});

This started to work for me in NextJS when I removed the http://localhost:3000/public part. I copied the node_modules/@ffmpeg/core/dist folder into public and renamed it ffmpeg_core_dist for clarity. Then

import { createFFmpeg, fetchFile } from "@ffmpeg/ffmpeg";
const ffmpeg = createFFmpeg({ log: true, corePath: "/ffmpeg_core_dist/ffmpeg-core.js" });

worked locally. But on production I got the error Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined which I was able to fix by adding these headers to next.config.js:

async headers() {
    return [
        {
            source: "/", // change to appropriate path
            headers: [
                {
                    key: "Cross-Origin-Embedder-Policy",
                    value: "require-corp",
                },
                {
                    key: "Cross-Origin-Opener-Policy",
                    value: "same-origin",
                },
            ],
        },
    ];
},

But this is not a perfect solution because SharedArrayBuffer is not defined still happens sometimes on page load and a reload is needed to get ffmpeg to load. Also it has other issues mentioned here. This all has to do with the security of SharedArrayBuffer that goes above my head.

8reactions
votruongancommented, Mar 1, 2022

For anyone using react-scripts or create-react-app to run React, you can send headers manually by using a customized middleware (https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually).

First, install http-proxy-middleware:

npm install http-proxy-middleware --save

or

yarn add http-proxy-middleware

Then, create src/setupProxy.js file and put our logic in there:

module.exports = function (app) {
    app.use(function (request, response, next) {
        response.setHeader("Cross-Origin-Opener-Policy", "same-origin");
        response.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
        next();
    });
};

Read more comments on GitHub >

github_iconTop Results From Across the Web

FFmpeg.wasm stopped working after adding cross origin ...
After that, now when I try to run the code I just got Uncaught ReferenceError: FFmpeg is not defined. The error is happening...
Read more >
ffmpegjs - Bountysource
CreateFFmpegCore is not undefined. $ 0 ... In Next.js, Uncaught (in promise) ReferenceError: _ is not defined will happen with valid configuration.
Read more >
FFmpeg.wasm, a pure WebAssembly / Javascript port of ...
wasm is not as fast as FFmpeg, but it might come in handy for certain use cases. In this post, I would like...
Read more >
Uncaught ReferenceError: unityFramework is not defined at ...
Bug Uncaught ReferenceError: unityFramework is not defined at HTMLScriptElement.script.onload (WebGL).
Read more >
[Showoff saturday] An online tool that allow you to cut a video ...
Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined createFFmpegCore 9e6bab1c-3237-451a-9bca-dafd8166b9e5:22 e ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found