ApeironTsuka / node-webpmux

A mostly 1:1 re-implementation of webpmux as a Node module in pure Javascript. Only thing currently missing is a command-line version.
GNU Lesser General Public License v3.0
26 stars 8 forks source link

RuntimeError: no such file or directory, open libwebp.wasm #22

Open jordan-loeser opened 1 year ago

jordan-loeser commented 1 year ago

Hey there,

I'm getting the following RuntimeError when trying to migrate this library to be run in a NextJS API route, and I'm hoping someone here might be able to help. I'm using the same exact code as I had previously functioning in NodeJS, and using the nodejs runtime in NextJS. It looks like something is getting messed up with the import path for libwebp.wasm.

I'm hoping someone may be able to help me get to the bottom of this. Here is the error:

Aborted(Error: ENOENT: no such file or directory, open 'PROJECT_DIRECTORY/.next/server/app/api/render/nyctrainsign/libwebp.wasm')
failed to asynchronously prepare wasm: RuntimeError: Aborted(Error: ENOENT: no such file or directory, open 'PROJECT_DIRECTORY/.next/server/app/api/render/nyctrainsign/libwebp.wasm'). Build with -s ASSERTIONS=1 for more info.
Aborted(RuntimeError: Aborted(Error: ENOENT: no such file or directory, open 'PROJECT_DIRECTORY/.next/server/app/api/render/nyctrainsign/libwebp.wasm'). Build with -s ASSERTIONS=1 for more info.)
- error RuntimeError: Aborted(Error: ENOENT: no such file or directory, open 'PROJECT_DIRECTORY/.next/server/app/api/render/nyctrainsign/libwebp.wasm'). Build with -s ASSERTIONS=1 for more info.
    at abort (webpack-internal:///(rsc)/./node_modules/node-webpmux/libwebp/libwebp.js:495:21)
    at getBinary (webpack-internal:///(rsc)/./node_modules/node-webpmux/libwebp/libwebp.js:522:17)
    at eval (webpack-internal:///(rsc)/./node_modules/node-webpmux/libwebp/libwebp.js:549:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

For context, I am using the following on a Mac running Apple Silicon.

ApeironTsuka commented 1 year ago

I'm not really sure on this one. Some quick Google suggests it may be related to using Webpack 5 if you are? A possible work-around could be symlinking libwebp.wasm to that path. Apologies that I couldn't be more help.

jordan-loeser commented 1 year ago

Thanks for taking a look @ApeironTsuka! No luck on this yet on my end, but it looks like this is triggered when I call the static WebP.Image.initLib().

jordan-loeser commented 1 year ago

It feels like this must be something to do with what's happening here 🤔 https://github.com/ApeironTsuka/node-webpmux/blob/b438517c9042a11e6870a4cba4c554f413aee64f/webp.js#L361-L368

jordan-loeser commented 1 year ago

It looks like this might be a known issue with NextJS: https://github.com/JamieMason/blurhash-to-css/issues/1