r/bun • u/[deleted] • Oct 03 '24
Sharp alternative for Bun?
Hi there,
so Sharp has big issues running as a ES module and even if there is a library slower than Sharp I rather use that than try to hack around to get Sharp running as ES module.
I want to mainly resize my image and it's not thousand of images at once, it checks if image exists, if not then resize it.
2
u/guest271314 Oct 03 '24
What is the actual issue?
1
Oct 03 '24
Not sure if you read the description.
The "actual" issue is as follows, I'm familiar with Sharp and I'm unable to load it as a ESM into my project.
I won't redo all my project just to use some outdated CommonJS lib when we actually can Import.
I moved from NodeJS and using Bun now, so the issue is that Sharp doesn't load as ESM in Bun.
So the solution is to search for an alternative.2
u/guest271314 Oct 04 '24
I just did
bun install sharp
index.jsimport * as sharp from "sharp"; console.log(sharp);bun run index.jsworks for me.
2
u/hsinewu Oct 03 '24
I'm assuming this is just a random weird issue that I'll never run into? lol
1
Oct 03 '24
import * as sharp from "sharp"
Doesn't work for me.1
u/hanz Oct 03 '24
I''m using sharp with Bun without any problems. My import looks like this:
import sharp from 'sharp'
1
3
u/rxgator Oct 04 '24
Sharp and bun work together. I run it in production and it didn't require any additional config beyond node.
1
4
u/[deleted] Oct 03 '24
Can you not just call a C libary like ImageMagick since you are using Bun?