Skip to content

fix: replace require() with dependency injection for ESM compatibility#2

Open
vdg wants to merge 1 commit intoMapaor:mainfrom
vdg:fix/esm-require-bug
Open

fix: replace require() with dependency injection for ESM compatibility#2
vdg wants to merge 1 commit intoMapaor:mainfrom
vdg:fix/esm-require-bug

Conversation

@vdg
Copy link

@vdg vdg commented Mar 5, 2026

Fixes #1

Summary

Fixes the require() usage in inline-renderer.ts that breaks in strict ESM environments (Bun, Deno, Node.js with experimental VM modules).

Problem

The footnote rendering code used require() to lazily import renderBlock and avoid circular dependencies at module load time. This fails in strict ESM environments where require() is not available.

Solution

Use dependency injection instead:

  1. Add BlockRenderer type to types.ts
  2. Add optional renderBlock to RenderContext
  3. Inject renderBlock via context from markdown2typst.ts
  4. Use context.renderBlock in inline-renderer.ts

Testing

  • All 99 existing tests pass
  • TypeScript compiles without errors
  • Build succeeds for both minified and standard bundles

Breaking Changes

None. The public API is unchanged.

The footnote rendering code used require() to avoid circular imports,
but require() is not available in strict ESM environments (Bun, Deno,
Node.js with type: module in strict mode).

This change:
- Adds BlockRenderer type to types.ts
- Adds optional renderBlock to RenderContext
- Injects renderBlock via context from markdown2typst.ts
- Uses context.renderBlock in inline-renderer.ts

Maintains the same circular import avoidance while being fully ESM-compatible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

require() in ESM module breaks in strict ESM environments

1 participant