Install
In Node,@reductoai/docx needs Node.js 20.11 or newer.
Install these packages with an install token from the Office SDK page in Studio. Studio gives you the two
.npmrc lines:Layout engine (Node)
Your package manager installs one native engine package for your platform as an optional dependency, e.g.@reductoai/docx-engine-linux-x64-gnu. npm, pnpm (also with hoist=false), Yarn (Plug’n’Play and node-modules), Bun and Deno (npm: specifiers) install and load it.
The Linux packages need glibc 2.17 or newer. Node.js itself needs a newer glibc, so they load on the AWS Lambda Node.js runtimes (Amazon Linux 2023), Debian 11, RHEL 8 and Ubuntu 20.04.
Without a native engine, the library lays out with the bundled engine.wasm: the same engine as WebAssembly, slower.
The native engine loads in
worker_threads: workers can start, convert and exit one after another or side by side in one process.
Optional native modules (Node)
The Node build uses native modules where they are faster. They are optional; the library uses a slower fallback when a module is missing.Bundlers
- The package has a
browserexport condition. Vite, webpack and esbuild select the browser build when they bundle for a page. You need no alias or polyfill. - Browser layout runs in
@reductoai/docx/engine.wasm. Vite, webpack and Next.js copy the file into your build. With another bundler, such as esbuild, give its URL. See The layout engine. - Vite 7 and older build workers as
iife, which the editor’s worker does not fit: setworker: { format: "es" }invite.config. - Keep
@reductoai/docx/nodeout of client code. In Next.js, add@reductoai/docxand@reductoai/portable-fontstoserverExternalPackagesso the server bundle keeps native modules on disk. - Layout is CPU work. In a page, run it in a Web Worker if the document is large. The editor does this for you (see Editor).
Smoke test
npx tsx smoke.ts (or compile it first). Open hello.pdf.