Wasm on opennext/cloudflare causes issues with Webpack
I'm trying to use @cf-wasm/photon (an Image manipulation library) with opennext
well the reason is Cloudflare Images having too expensive and unreasonable pricing compared to other products so as a cost saving measure in a personal project I wanted to avoid Images product much as possible and reimplement It's functionality through Workers and R2.
What I do:
- Send request to NextJS api endpoint from UI
- Attempt to resize and crop
- Upload to R2
- Send to an AI image moderation service to check if the image is offensive
- Send a request to internal API written in .NET Core updating profile fields (NextJS itself isn't my "real" backend here, It's just BFF pattern)
Problem is opennext/cloudflare and Wasm don't go well together. It runs and compiles perfectly fine locally but when deployed break aparts with no obvious warning, it also swallows errors so you can't debug it. The next api simply returns 500.
if @cf-wasm/photon/next used instead of @cf-wasm/photon (no error in dev but doesn't work in production) this error happens
Workarounds:
Create another worker and map it using Routes
Move resize logic to .NET but this would break roles of stack
0 Replies