Skip to content

bug: @kreuzberg/wasm fails to bundle in Next.js — imports node:module, fs/promises, worker_threads #823

@benjifriedman

Description

@benjifriedman

Description

The @kreuzberg/wasm package can't be used in a Next.js app (v16, Turbopack or webpack) because the main entry point (dist/index.js) statically imports Node.js-only modules that don't exist in browser environments.

Errors

With Turbopack (Next.js 16 default):

NftJsonAsset: cannot handle filepath worker_threads

With webpack (next build --webpack):

Module not found: Can't resolve 'fs/promises'
Module not found: Can't resolve 'worker_threads'
Module not found: Can't resolve 'node:module'

Import trace:

node:module
  → @kreuzberg/wasm/dist/pdfium.js
  → @kreuzberg/wasm/dist/index.js

Steps to reproduce

npx create-next-app@latest test-app
cd test-app
npm install @kreuzberg/wasm

Add to any client component:

const { initWasm, extractBytes } = await import("@kreuzberg/wasm");

Run npm run build → build fails.

Relevant files and configuration

- `@kreuzberg/wasm` version: latest
- Next.js 16.1.6
- Node.js 22
- macOS

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions