Menu

1 / 2

Next.js Bundling a wasm Package Breaks Only in Production

DEV Community: frontend·cometa-kaito·9 days ago
#S2LUpauL
#devtofrontend#devto#dev#path#wasm
Long article (558 words) — no AI summary yet.
Reading 0:00
15s threshold

Conclusion

An npm package that loads a wasm file breaks when included in the standard Next.js bundle. If the package resolves its wasm by relative path internally, bundling changes what that path is relative to, and it fails at runtime with a type error.

The fix is to exclude the package from bundling with serverExternalPackages and to explicitly include the wasm itself in the deployment with outputFileTracingIncludes — both, not one.

Symptom

Requests issuing a document PDF return 502 in production only

The same failure reproduces locally under next build && next start (production build mode)

The log shows this type error

TypeError: The "path" argument must be of type string … Received type number

Enter fullscreen mode

Exit fullscreen mode

A type error where a string path should be passed. Reviewing the calling code, the value being passed is a string.

Cause

PDF generation uses HarfBuzz ( subset-font ) to build a font reduced to just the characters used, avoiding dropped CJK glyphs.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.