-
-
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
Add support to ES Modules #2981
Comments
|
Do you know if the wrapper approach outlined in https://nodejs.org/api/packages.html#approach-1-use-an-es-module-wrapper will work with Nuxt Nitro? |
|
It should work, I think. Otherwise, you can use https://github.com/unjs/mlly to port sharp into ESM 😛 @pi0 any suggestions? |
|
@Rigo-m Sharp can be imported inside Node.js ESM files and also working fine with Nuxt Nitro (the only limitation is you cannot deploy to Workers because of Node.js bindings). BTW you might like to use ipx which is based on Sharp but easier to integrate. Check this example: https://codesandbox.io/s/quirky-currying-3259v?file=/server/api/ipx.ts @lovell While Node.js ESM can work with CJS libraries and bundlers like webpack/rollup allow mixed syntax (that's how nitro workers) it would be nice if Sharp also adds exports field. This can make support less hacky and more ESM native. If you want me can make a PR to improve packages' ESM support. Some of popular packages even considered being esm-only. |
|
Thanks for confirming, a PR to add a thin ESM wrapper and suitable And thank you Pooya for all your work on Nuxt and the Vue ecosystem! |
|
Hi @lovell. Just pinging to say still would love to contribute to this for ESM support! @danielroe is also an ESM expert who might help on this as well :) |
|
@pi0 Do you happen to have an example with sharp and nuxt nitro somewhere? Running into problems, where sharp is a dependency of a package that is imported for a server side api in nuxt 3. |
|
Usage is in sandbox comment above but official Nuxt3 integration is coming soon with Image module. |
|
looking forward to this support |
|
I'm trying to make it work with esbuild, but I always get __dirname is not defined :( |
What are you trying to achieve?
Use Sharp in a nuxt nitro environment
What would you expect the API to look like?
Sharp should export an .mjs file so that it can be used in environments that doesn't support .cjs
What alternatives have you considered?
None but any suggestion is welcomed
The text was updated successfully, but these errors were encountered: