Niels-IO / next-image-export-optimizer

Use Next.js advanced <Image/> component with the static export functionality. Optimizes all static images in an additional step after the Next.js static export.
413 stars 51 forks source link

Package doesn't work with bun #177

Closed temp4422 closed 5 months ago

temp4422 commented 8 months ago

When using npm everything work as expected. When using bun, got this error:

/Users/user/dev/my-nextjs-app/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:
- /Users/user/dev/my-nextjs-app/node_modules/sharp/lib/sharp.js
- /Users/user/dev/my-nextjs-app/node_modules/sharp/lib/constructor.js
- /Users/user/dev/my-nextjs-app/node_modules/sharp/lib/index.js
- /Users/user/dev/my-nextjs-app/node_modules/next-image-export-optimizer/dist/optimizeImages.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> (/Users/user/dev/my-nextjs-app/node_modules/sharp/lib/sharp.js:37:9)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1201:32)
    at Module._load (node:internal/modules/cjs/loader:1017:12)
    at Module.require (node:internal/modules/cjs/loader:1229:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/Users/user/dev/my-nextjs-app/node_modules/sharp/lib/constructor.js:11:1)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)

Node.js v21.0.0
error: "env" exited with code 1 (SIGHUP)

Info:

Niels-IO commented 8 months ago

Hi @webdev4422,

this is related to sharp.js not working 100% out-of-the-box with bun. When this issue progresses, we can take a look at it again: https://github.com/lovell/sharp/issues/3511

donnikitos commented 6 months ago

@webdev4422 adding

  "trustedDependencies": [
    "sharp"
  ],

and a post-install hook

  "scripts": {
    ...
    "postinstall": "cd node_modules/sharp && bun install && cd ../..",
    ...
  },

to your package.json and reinstalling sharp should resolve the problem ;)

Niels-IO commented 5 months ago

Hi @webdev4422,

Could you try the latest version of this package? In my test, it does work now with Bun

temp4422 commented 5 months ago

Hi @webdev4422,

Could you try the latest version of this package? In my test, it does work now with Bun

Confirm 🎉 Works with bun. Thank you!

Steps: Remove rm node_modules package-lock.json .next out Change in package.json to "next-image-export-optimizer": "^1.12.2" Run bun install && bun run build