PlayForm / Compress

🗜️ Compress —
https://playform.github.io/Compress/
Other
510 stars 12 forks source link

Incompatible with Bun #193

Closed designorant closed 1 year ago

designorant commented 1 year ago

Background

Bun is an all-in-one JavaScript runtime & toolkit that's officially mentioned in Astro docs, albeit with caution.

Issue

This package doesn't work when using Bun due to one of its dependencies, namely sharp.

It is a known issue:

Logs

When running bun run build:

❯ bun run build
$ astro build
/PATH_TO_PROJECT/node_modules/astro-compress/node_modules/sharp/lib/sharp.js:37
  throw new Error(help.join('\n'));
        ^

Error:
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-darwin-arm64v8.node'
Require stack:
- /PATH_TO_PROJECT/node_modules/astro-compress/node_modules/sharp/lib/sharp.js
- /PATH_TO_PROJECT/node_modules/astro-compress/node_modules/sharp/lib/constructor.js
- /PATH_TO_PROJECT/node_modules/astro-compress/node_modules/sharp/lib/index.js

Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current darwin-arm64v8 runtime: "npm install --platform=darwin --arch=arm64v8 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (PATH_TO_PROJECT/node_modules/astro-compress/node_modules/sharp/lib/sharp.js:37:9)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (PATH_TO_PROJECT/node_modules/astro-compress/node_modules/sharp/lib/constructor.js:11:1)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)

Node.js v20.6.1
error: script "build" exited with code 1 (SIGHUP)

When running bun --bun run build:

❯ bun --bun run build
$ astro build
1:29:40 PM [vite] Error when evaluating SSR module /PATH_TO_PROJECT/astro.config.mjs: failed to import "astro-compress"
|- undefined

[astro] Unable to load your Astro config

 error
  Something went wrong installing the "sharp" module

  Cannot find module "../build/Release/sharp-darwin-arm64v8.node" from "PATH_TO_PROJECT/node_modules/astro-compress/node_modules/sharp/lib/sharp.js"

  Possible solutions:
  - Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
  - Install for the current darwin-arm64v8 runtime: "npm install --platform=darwin --arch=arm64v8 sharp"
  - Consult the installation documentation: https://sharp.pixelplumbing.com/install
  Hint:
    Browser APIs are not available on the server.

    If the code is in a framework component, try to access these objects after rendering using lifecycle methods or use a `client:only` directive to make the component exclusively run on the client.

    See https://docs.astro.build/en/guides/troubleshooting/#document-or-window-is-not-defined for more information.

error: script "build" exited with code 1 (SIGHUP)
NikolaRHristov commented 1 year ago

Hi, as a temporary solution, while this gets fixed, you can use the no-sharp branch of AstroCompress

npm install -D -E astro-community/astro-compress#no-sharp

https://github.com/astro-community/AstroCompress/tree/no-sharp

designorant commented 1 year ago

Thanks @NikolaRHristov!

Can confirm the following leads to a successful bun build:

bun add astro-community/AstroCompress#no-sharp