supabase / edge-runtime

A server based on Deno runtime, capable of running JavaScript, TypeScript, and WASM services.
MIT License
640 stars 55 forks source link

npm:sharp not working #391

Closed gipde closed 1 month ago

gipde commented 1 month ago

Bug report

Describe the bug

when i import npm:sharp the runtime is unable to load the module.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

import process from "node:process";
import os from "node:os";
console.log("Hello, Deno!", os.platform(), os.arch(), process.cwd());
import sharp from "npm:sharp";
console.log(Object.keys(sharp.format));

Error-Text:

crates/base/src/server.rs-466: DEBUG edge-runtime is listening on 0.0.0.0:9000
crates/base/src/rt_worker/implementation/default_handler.rs-45: runtime has escaped from the event loop unexpectedly: event loop error: Error: Could not load the "sharp" module using the linux-arm64 runtime
undefined: Not supported
Possible solutions:
- Ensure optional dependencies can be installed:
    npm install --include=optional sharp
    yarn add sharp --ignore-engines
- Ensure your package manager supports multi-platform installation:
    See https://sharp.pixelplumbing.com/install#cross-platform
- Add platform-specific dependencies:
    npm install --os=linux --cpu=arm64 sharp
- Consult the installation documentation:
    See https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/sharp/0.33.4/lib/sharp.js:114:9)
    at Object.<anonymous> (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/sharp/0.33.4/lib/sharp.js:117:4)
    at Module._compile (node:module:657:34)
    at Module._extensions..js (node:module:671:10)
    at Module.load (node:module:595:32)
    at Module._load (node:module:482:12)
    at Module.require (node:module:607:19)
    at require (node:module:713:16)
    at Object.<anonymous> (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/sharp/0.33.4/lib/constructor.js:10:1)
    at Object.<anonymous> (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/sharp/0.33.4/lib/constructor.js:452:4)
/usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.21.11/src/common_state.rs-498: DEBUG Sending warning alert CloseNotify

Additional context

If i run it with deno the module is working as expected, with the following output:

❯ deno run -A index.js
Hello, Deno! darwin arm64 /Users/werner/src/baumkataster/contrib/birnbaeume/supabase/functions/hello-world
[
  "jpeg",   "png",
  "webp",   "tiff",
  "magick", "openslide",
  "dz",     "ppm",
  "fits",   "gif",
  "svg",    "heif",
  "pdf",    "vips",
  "jp2k",   "jxl",
  "raw"
]

it also works if i run it in a docker-container with deno

❯ docker run -it -v ./:/mnt  denoland/deno run -A /mnt/index.js
Hello, Deno! linux arm64 /
[
  "jpeg",   "png",
  "webp",   "tiff",
  "magick", "openslide",
  "dz",     "ppm",
  "fits",   "gif",
  "svg",    "heif",
  "pdf",    "vips",
  "jp2k",   "jxl",
  "raw"
]
mansueli commented 1 month ago

This is listed in the limitations:

Node Libraries that require multithreading are not supported. Examples: libvips, sharp.

https://supabase.com/docs/guides/functions/limits#other-limits--restrictions

gipde commented 1 month ago

thx for update