ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
13.49k stars 775 forks source link

Added type=module to @ffmpeg/util package.json #627

Open asticode opened 8 months ago

asticode commented 8 months ago

I'm using Vite and pnpm and when trying to use @ffmpeg/util I'm getting this error:

import { ERROR_RESPONSE_BODY_READER, ERROR_INCOMPLETED_DOWNLOAD, } from "./errors.js";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Adding "type": "module" to @ffmpeg/util's package.json fixes the error 👍

netlify[bot] commented 8 months ago

Deploy Preview for ffmpegwasm canceled.

Name Link
Latest commit d76af5691716b3d28c5e38f3b0734f5a5248d05d
Latest deploy log https://app.netlify.com/sites/ffmpegwasm/deploys/6550a9f339a8440008200adb
PaulieScanlon commented 7 months ago

Just a little +1 from me. I'm seeing the same error when using Remix.

PaulieScanlon commented 7 months ago

I ran into the same problem. If you need a work around, this is what worked for me.

  1. Install patch-package

    npm install patch-package --save -dev
  2. Add postinstall script to package.json

// package.json

  "scripts": {
    ...
    "postinstall": "patch-package"
  },
  1. Run patch-package with the --exclude flag
npx patch-package --exclude 'nothing' @ffmpeg/util
  1. Commit the changes You should then see a new .patch file is created in /patches

E.g

// @ffmpeg+util+0.12.1.patch

diff --git a/node_modules/@ffmpeg/util/package.json b/node_modules/@ffmpeg/util/package.json
index 3afedb4..0a48d3a 100644
--- a/node_modules/@ffmpeg/util/package.json
+++ b/node_modules/@ffmpeg/util/package.json
@@ -3,6 +3,7 @@
   "version": "0.12.1",
   "description": "browser utils for @ffmpeg/*",
   "main": "./dist/cjs/index.js",
+  "type": "module",
   "types": "./dist/cjs/index.d.ts",
   "exports": {
     ".": {

Hope that helps someone!