Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with Bun #193

Closed
designorant opened this issue Sep 19, 2023 · 2 comments
Closed

Incompatible with Bun #193

designorant opened this issue Sep 19, 2023 · 2 comments
Assignees
Labels

Comments

@designorant
Copy link

designorant commented Sep 19, 2023

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
Copy link
Member

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
Copy link
Author

Thanks @NikolaRHristov!

Can confirm the following leads to a successful bun build:

bun add astro-community/AstroCompress#no-sharp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants