raaymax
raaymax7d ago

How to workaround `deno compile` binary file limitations?

In my app I'm using sharp and after compile it looses the ability to load dll.
❯ ./server
error: Uncaught (in promise) Error: Could not load the "sharp" module using the darwin-arm64 runtime
undefined: dlopen(/var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/@img+sharp-darwin-arm64@0.33.0/node_modules/@img/sharp-darwin-arm64/lib/sharp-darwin-arm64.node, 0x0001): tried: '/var/folders/4f/6rr3fjvx2wq742xvnz3lf17)
Possible solutions:
- Add platform-specific dependencies:
npm install --os=darwin --cpu=arm64 sharp
or
npm install --force @img/sharp-darwin-arm64
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/sharp.js:85:9)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/sharp.js:88:4)
at Module._compile (node:module:736:34)
at Object.Module._extensions..js (node:module:757:11)
at Module.load (node:module:655:32)
at Function.Module._load (node:module:523:13)
at Module.require (node:module:674:19)
at require (node:module:801:16)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/constructor.js:10:1)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/constructor.js:446:4)
❯ ./server
error: Uncaught (in promise) Error: Could not load the "sharp" module using the darwin-arm64 runtime
undefined: dlopen(/var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/@img+sharp-darwin-arm64@0.33.0/node_modules/@img/sharp-darwin-arm64/lib/sharp-darwin-arm64.node, 0x0001): tried: '/var/folders/4f/6rr3fjvx2wq742xvnz3lf17)
Possible solutions:
- Add platform-specific dependencies:
npm install --os=darwin --cpu=arm64 sharp
or
npm install --force @img/sharp-darwin-arm64
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/sharp.js:85:9)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/sharp.js:88:4)
at Module._compile (node:module:736:34)
at Object.Module._extensions..js (node:module:757:11)
at Module.load (node:module:655:32)
at Function.Module._load (node:module:523:13)
at Module.require (node:module:674:19)
at require (node:module:801:16)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/constructor.js:10:1)
at Object.<anonymous> (file:///var/folders/4f/6rr3fjvx2wq742xvnz3lf1740000gn/T/deno-compile-server/Chat/node_modules/.deno/sharp@0.33.0/node_modules/sharp/lib/constructor.js:446:4)
Is there any way to workaround this problem?
2 Replies
bartlomieju
bartlomieju7d ago
DLLs are not supported in deno compile right now. Sadly there's no workaround atm
jeff.hykin
jeff.hykin4d ago
Well theres one hacky workaround. I made a tool last year https://deno.land/x/binaryify that lets us ES import .dylib files as a Uint8Array. We can then write that array to a temp file at runtime and then dlopen that file. It would look like: 1. Install binaryify 2. Run binaryify -- ./your.dylib 3. Instead of calling .dlopen do
import dylibBytes from "./your.dylib.binaryified.js"

let tempFile = await Deno.makeTempFile()
await Deno.writeFile(tempFile, dylibBytes)

Deno.dlopen(file)
import dylibBytes from "./your.dylib.binaryified.js"

let tempFile = await Deno.makeTempFile()
await Deno.writeFile(tempFile, dylibBytes)

Deno.dlopen(file)
Binaryify (as of today) will auto-update the "./your.dylib.binaryified.js" file every time time the "./your.dylib" file changes