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.…