Skip to content

ESM Web Worker Importing CommonJS Module Failure [Only in Production] #12287

@absurdprofit

Description

@absurdprofit

Describe the bug

I have a project that uses a forked version of ffmpeg.wasm. The project is packaged using npm pack and the resulting .tgz file is used to install ffmpeg. When I use this package in a web worker using ESM import.
import { createFFmpeg } from "@ffmpeg/ffmpeg"; everything is fine in development. However after running npm run build and serving the app using python3 -m http.server 3000 the worker crashes with this error:
error

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

"ES Modules may not"

Environment

Environment Info:

  current version of create-react-app: 5.0.1
  running from C:\Users\nayja\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app

  System:
    OS: Windows 10 10.0.19044
    CPU: (4) x64 Intel(R) Core(TM) i3-8130U CPU @ 2.20GHz    
  Binaries:
    Node: 17.8.0 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 100.0.4896.88
    Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.39)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    react: ^18.0.0 => 18.0.0 
    react-dom: ^18.0.0 => 18.0.0 
    react-scripts: 5.0.1 => 5.0.1 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. Create a react app using npx create-react-app app --template typescript
  2. Install ffmpeg.wasm from
  3. Instantiate ffmpeg inside a web worker using createFFmpeg (imported with ESM syntax)
  4. Instantiate said web worker with type "module"
  5. Run npm run build and serve the resulting index.html

Expected behavior

  1. FFmpeg.wasm should be instantiated with no errors.
  2. FFmpeg should log [info] use ffmpeg.wasm v0.10.2 to the console.

Actual behavior

  1. The web worker crashes
  2. This error is logged to the console: error

Reproducible demo

A minimal reproducible demo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions