`require("beautiful-mermaid")` in Node.js throws `ERR_PACKAGE_PATH_NOT_EXPORTED`

Author: yhattCreated Mar 21, 2026Updated Aug 30, 2026

Thanks for developing this. Synchronous mermaid rendering and zero DOM dependencies is just what I want.

The pre-built JS in v1.1.2 is also awesome, but it is not compatible with require() statement in the latest Node.js.

bash
$ node
Welcome to Node.js v22.22.0.
Type ".help" for more information.
> require('beautiful-mermaid')
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/yhatt/Programs/project/node_modules/beautiful-mermaid/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:313:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:603:13)
    at resolveExports (node:internal/modules/cjs/loader:650:36)
    at Function._findPath (node:internal/modules/cjs/loader:717:31)
    at Function._resolveFilename (node:internal/modules/cjs/loader:1369:27)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

And some bundlers that correctly recognize the exports field in package.json throw the same error. The following output is the error from Rolldown:

 ERROR  Error: Build failed with 1 error:

[RESOLVE_ERROR] Error: Could not resolve 'beautiful-mermaid' in src/mermaid/loader.ts
    ╭─[ src/mermaid/loader.ts:10:15 ]
    │
 10 │       require('beautiful-mermaid')
    │               ─────────┬─────────  
    │                        ╰─────────── Package subpath is not defined by exports
    │ 
    │ Help: 'src/mermaid/loader.ts' is imported by the following path:
    │         - src/mermaid/loader.ts
    │         - src/mermaid/mermaid.ts
    │         - src/index.ts
────╯

Motivation: I want to use require() to import module lazily (instead of using import() for completely synchronous rendering).

Source: lukilabs/beautiful-mermaid