Skip to content
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

Fails to load WASM file in Next.js app router #1

Open
cbratschi opened this issue Aug 23, 2023 · 2 comments
Open

Fails to load WASM file in Next.js app router #1

cbratschi opened this issue Aug 23, 2023 · 2 comments

Comments

@cbratschi
Copy link

I am getting the following error while using blurhash-to-css in the Next.js app router:

- error Error: ENOENT: no such file or directory, open '/.../.next/server/app/[lang]/[[...slug]]/blurhash_to_css_bg.wasm'
    at Object.openSync (node:fs:592:3)
    at Object.readFileSync (node:fs:460:35)
    at eval (webpack-internal:///(rsc)/../../node_modules/blurhash-to-css/pkg/blurhash_to_css.js:181:65)
    at (rsc)/../../node_modules/blurhash-to-css/pkg/blurhash_to_css.js (/.../.next/server/app/[lang]/[[...slug]]/page.js:1808:1)
    at __webpack_require__ (/....next/server/webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/../../node_modules/blurhash-to-css/index.js:6:27)

Next.js tried to load blurhash_to_css_bg.wasm from the .next/server folder instead of the pkg folder of the module.

The blurhash-to-css code looks correct:

const path = require('path').join(__dirname, 'blurhash_to_css_bg.wasm');
const bytes = require('fs').readFileSync(path);

Therefore this looks like a Next.js Webpack bundling issue.

@cbratschi
Copy link
Author

Could be related to:

vercel/next.js#25852
vercel/next.js#35637

A pure JavaScript version would be the easiest way to use this in a Next.js SSR component.

@cbratschi
Copy link
Author

Ported the code to TypeScript for anyone interested: https://gist.github.com/cbratschi/a98c3b6270caa561c051af7cb17edb8b

However, data is larger than a inlined data URL image and there was some banding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant