Closed kanashimia closed 11 months ago
It looks like you're trying to use the library in Node.js and/or Bun. As noted in the library description and README – its intended usage is for the browser only.
Squoosh already provides a Node.js library if you'd like to use that, @squoosh/lib. There are also many other popular image focused libraries like sharp. Hopefully one of them works for your image service solution 🤞 , best of luck!!
None of those libraries really work for my use cases, hence why I was trying out your library, my intention was to get an image optimisation working on cloudflare pages with Astro SSR, there really seems like there is no single library that works. Well, I haven't really tried to actually run this library there, situation may be different, but would be nice to have one general solution. And squoosh is deprecated, by the name I thought that this library was a successor to squoosh or something. Better note explicitly that the library is not intended for use in node, it is not really clear from description.
Thanks @kanashimia I appreciate the feedback, I want to confirm that it's not clear from the first few sentences of the library's README.
Other than explicitly stating "this is not for Node.js", I'm at a loss how much more clearer I can make it 😅
My thoughts were somewhere along the lines of: >this library advertises for support in the Browser AND "V8 runtimes" >node uses V8 runtime >hmm, that was a weird way to word it, but should work >other bits are just about that it supports browser too >very cool, awesome library, works everywhere :)
Seems like other users are confused too (#36), I'll make that more explicit. Thanks for the feedback and I hope you found a work around! 🤞
Describe the bug With Vite SSR first thing that you encounter is that you can't import jSquosh at all, it fails with:
Importing using relative paths worked.
optimizeDeps.exclude
didn't help in any way.OK, than with helpful suggestion of the people from the Astro chat I found that adding jSquash to
ssr.noExternal
fixed that.But I couldn't fix the following: On Node 16 and Bun during decoding it fails with:
On Node 20 it fails with:
As I know Vite has knows problems with
fetch
during SSR, hence I tried importing it manually.(this code is also commented out in the stackblitz reproduction example)
But now there is this error: Node 20:
Bun:
Vite doesn't support importing wasm same way as in the cloudflare worker examples, there is a plugin to fix that, but it doesn't work. Is my API usage valid at all?
To Reproduce Steps to reproduce the behavior:
Reproduction URL https://stackblitz.com/edit/vitejs-vite-ndaywm?file=main.js
Module Versions Latest of them all
Additional context I was trying to create an image service for Astro, but was blocked by this. I found out that
vite-node
uses SSR too, hence it is used here for reproduction as it is much simpler than using framework framework framework. Just noting that it worked in Astro duringastro dev
, the problem there is withastro build
.