-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support for bun runtime #3511
Comments
This will be dependent on oven-sh/bun#158 and oven-sh/bun#606 |
Great thanks. I suspect those issues will be unblocked in the next couple months at the rate they're going. I'll try to remember to update this thread once ready. |
@lovell , would you be able to narrow down what parts of oven-sh/bun#158 are lacking in order for sharp to function? |
@birkskyum It looks like almost all of Node-API has been implemented in Bun during the last 6 months - perhaps someone can test it again? |
Okay, interesting that it could be resolved already. The other issue mentioned breaks on installation (oven-sh/bun#606), so let's assess the situation when that is fixed. |
Yes, I was pleasantly surprised to see sharp working on Bun v0.6.14! This was based on some very simple scripts I was using to keep tabs on this progress, not a test of the full API. To @birkskyum point, this is possible as I'm using my own install script (with prebuilt binaries) to avoid all the |
Landing WebAssembly build #3522 would be a great step to resolve this too, as it would provide a very portable fallback with reduced performance. |
Can anyone give me a working example please? |
Once Bun 0.8.0 releases, Sharp will work (napi features sharp depends on is more stable/fixed a bad crash), though the NPM lifecycle script not running is still an issue, see oven-sh/bun#606 |
For now, you can manually run post install script |
@xhyrom , how do i run |
cd node_modules/sharp
bun install then wait until install and try to run your code again, it should work :D |
@xhyrom , it works directly on my machine, which is awesome, but when doing this within a Dockerfile I get: error: script not found "install/libvips"
error: script not found "install/can-compile" My entire dockerfile is: FROM oven/bun
WORKDIR /usr/repo
COPY . .
RUN bun install
RUN cd ./node_modules/sharp && bun install
EXPOSE 3001
CMD [ "bun", "--bun", "run", "./src/app.ts" ]
|
Seems like the script can be found by making the paths in sharp's package.json relative, so they are i.e. sharp: Installation error: detectLibc.versionSync is not a function. (In 'detectLibc.versionSync()', 'detectLibc.versionSync' is undefined)
sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies |
Not sure what to do, with npm you could do |
I realized that the bun runtime works with sharp, but that |
Normal Sharp install in Bun will likely be resolved by: Then sharp just has to be added in package.json as |
Can you try to put sharp into |
With latest canary, and sharp in trustedDependencies, I get this, and i think it's because it can't find the arm64 bundle:
|
Simply using |
I made a separate ticket for supporting bun install. This ticket about bun runtime appear to be resolved. |
It is unlikely that bun not finding the .node file would cause a segfault. It sounds like we still have a crash to fix here |
Result of using the debug build: loader [parsing] /Users/admin/repos/backend/node_modules/stripe/esm/autoPagination.js
Loader [resolve] ./utils.js
loader [parsing] /Users/admin/repos/backend/node_modules/stripe/esm/multipart.js
Loader [resolve] ./utils.js
32 | if (loadedModule) {
33 | const [, loadedPackage] = loadedModule.match(/node_modules[\\/]([^\\/]+)[\\/]/);
34 | help.push(`- Ensure the version of sharp aligns with the ${loadedPackage} package: "npm ls sharp"`);
35 | }
36 | }
37 | throw new Error(help.join('\n'));
^
error:
Something went wrong installing the "sharp" module
Cannot find module "../build/Release/sharp-darwin-arm64v8.node" from "/Users/admin/repos/backend/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
at /Users/admin/repos/backend/node_modules/sharp/lib/sharp.js:37:8
at globalThis (/Users/admin/repos/backend/node_modules/sharp/lib/sharp.js:37:33)
at require (:1:20)
at /Users/admin/repos/backend/node_modules/sharp/lib/constructor.js:11:0
at globalThis (/Users/admin/repos/backend/node_modules/sharp/lib/constructor.js:439:17)
at require (:1:20)
at /Users/admin/repos/backend/node_modules/sharp/lib/index.js:6:6
at globalThis (/Users/admin/repos/backend/node_modules/sharp/lib/index.js:16:17)
at require (:1:20)
at /Users/admin/repos/backend/node_modules/join-images/lib/main.js:7:24
at globalThis (/Users/admin/repos/backend/node_modules/join-images/lib/main.js:89:18)
error: script "start" exited with code 1 (SIGHUP) |
@hendrikboeck in your message and code snippet you misspelled |
Please take a look at #3750 (comment) if you'd like to test an early pre-release of the forthcoming sharp v0.33.0 that should "just work" with Bun without setting |
@MariuzM #3848 will fix the wrong error being shown, but there's still an underlying problem. It looks like you're using some kind of bundler, so please ensure sharp is marked as "external" - see https://sharp.pixelplumbing.com/install#bundlers |
I don't think i use anything else apart what Bun already gives, my build command is i have tried but still same issue |
@MariuzM This looks like something specific to the |
@lovell https://github.com/MariuzM/bun-sharp and i have tested on Railway still same issue |
@MariuzM I fixed your problem. I think you forgot to add my Dockerfile: # https://hub.docker.com/r/oven/bun/tags?page=1&name=alpine
FROM oven/bun:1.0.12-alpine
RUN apk add vips-dev
WORKDIR /usr/src/app
COPY . .
RUN bun install
RUN bun run build
EXPOSE 3000
CMD bun run start my package.json: {
"name": "bun-sharp",
"version": "1.0.0",
"scripts": {
"d": "bun run --watch src/app.ts",
"b": "bun build ./src/app.ts --outdir ./build --target bun --external sharp",
"dev": "bun run d",
"build": "bun run b",
"start": "bun run ./build/app.js"
},
"dependencies": {
"elysia": "^0.7.28",
"semver": "^7.5.4",
"sharp": "0.33.0-alpha.11"
},
"devDependencies": {
"@types/node": "^20.9.1",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"bun-types": "^1.0.12",
"eslint": "8.54.0",
"eslint-plugin-import": "^2.29.0",
"prettier": "^3.1.0"
},
"module": "src/app.js"
} my .dockerignore:
|
@hendrikboeck thank you this worked. Its not that i forgot i just did not know 😁 |
@MariuzM Whilst it might appear to work, there is no need to add the |
@MariuzM Your container uses Alpine Linux but Bun does not officially support musl-based Linux - oven-sh/bun#918 In addition, Bun polyfills the |
@lovell thank you for taking time to explain in more detail, dint realized Alpine had missing packages. |
v0.33.0 is now available and tested working with the Bun JavaScript runtime on both Linux and macOS. |
THANK YOUUUUU |
Nope, it doesn't work. Could not load the "sharp" module using the linux-x64 runtime |
@7heMech It looks like you're using |
Feature request
What are you trying to achieve?
Bun seems like a good fit for sharp/vips with the focus on performance. The reduction in overhead from bindings could be a win with Bun. Currently no good image processing package for Bun, so this would given even more reason to promote sharp.
When you searched for similar feature requests, what did you find that might be related?
Nothing
What would you expect the API to look like?
n/a
What alternatives have you considered?
Currently use sharp extensively with Node.
Please provide sample image(s) that help explain this feature
n/a
The text was updated successfully, but these errors were encountered: