{"id":25177,"library":"docxml","title":"docxml","description":"docxml is a TypeScript library for building and parsing .docx files (OXML format) from scratch or from templates. The current stable version is 5.15.1, released actively with several updates per year. Key differentiators include support for both Node.js and Deno, JSX syntax for declarative document composition, template rendering with parameterized DOTX files, and coverage of features like tables, images, headers/footers, change tracking, comments, and reference fields. It provides a fully typed API and supports both programmatic and XML-driven document creation.","status":"active","version":"5.15.1","language":"javascript","source_language":"en","source_url":"https://github.com/wvbe/docxml","tags":["javascript","ooxml","docx","components","deno","node","jsx","typescript"],"install":[{"cmd":"npm install docxml","lang":"bash","label":"npm"},{"cmd":"yarn add docxml","lang":"bash","label":"yarn"},{"cmd":"pnpm add docxml","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export; in Node.js CJS requires destructuring: const { default: Docx } = require('docxml')","wrong":"const Docx = require('docxml')","symbol":"Docx","correct":"import Docx from 'docxml'"},{"note":"Named export; available from the main package","wrong":"const Paragraph = require('docxml/Paragraph')","symbol":"Paragraph","correct":"import { Paragraph } from 'docxml'"},{"note":"Named export for text content","symbol":"Text","correct":"import { Text } from 'docxml'"},{"note":"For Deno, import from 'https://deno.land/x/docxml/mod.ts' or via import map","wrong":"import Docx from 'docxml/src/index.ts'","symbol":"Docx","correct":"import { default as Docx } from 'docxml'"}],"quickstart":{"code":"import Docx, { Paragraph, Text } from 'docxml';\n\nasync function main() {\n  const doc = await Docx.fromJsx(\n    <Paragraph alignment=\"center\">\n      <Text>Hello World</Text>\n    </Paragraph>\n  );\n  await doc.toFile('hello.docx');\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Creates a simple DOCX file with a centered paragraph and saves it to disk."},"warnings":[{"fix":"Use `Docx.fromJsx()` or `Docx.fromNothing()` to create documents.","message":"In v5.0.0, the API changed from object-based to async component-based. Old `docx` create function removed.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Replace `new Document()` with `Docx.fromJsx()` or `Docx.fromNothing()`.","message":"The `Document` class is deprecated in favor of `Docx` namespace.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Add `/** @jsx Docx.jsx */` at the top of JSX files, or configure your transpiler to use `Docx.jsx` as the JSX factory.","message":"JSX requires a transpiler (e.g., Babel or TypeScript) and the `/** @jsx Docx.jsx */` pragma or equivalent configuration.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Use `const { default: Docx } = require('docxml')` or switch to ESM imports.","message":"In Node.js CommonJS, the default import must be destructured as `const { default: Docx } = require('docxml')` because the package exports ESM first.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Ensure the output directory exists before calling `toFile()`, or use `toBuffer()` and write the buffer yourself.","message":"Saving a file with `toFile()` may fail if the output directory doesn't exist. The library does not create directories automatically.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use the correct import map URL (e.g., from deno.land/x/docxml) or an npm specifier if using Node.","cause":"Using a Deno import map that references the package itself incorrectly.","error":"Error: self-referencing import map not allowed"},{"fix":"Use `const { default: Docx } = require('docxml')` or switch to ESM imports.","cause":"Using CommonJS `require('docxml')` without destructuring the default export.","error":"TypeError: Docx.fromJsx is not a function"},{"fix":"Add `/** @jsx Docx.jsx */` at the top of the JSX file, or configure your transpiler to use `Docx.jsx`.","cause":"Using JSX without the correct JSX pragma (e.g., `/** @jsx Docx.jsx */`).","error":"ReferenceError: React is not defined"},{"fix":"Create the directory before calling `toFile()`, or use `toBuffer()` and write manually after ensuring the path exists.","cause":"Output directory does not exist.","error":"Error: DOCX file not saved: ENOENT: no such file or directory, open '...'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}