Skip to content

Fix Node crashes from dynamic require in ESM bundle - #6

Merged
donnes merged 1 commit into
mainfrom
fix/esm-require
Oct 22, 2026
Merged

donnes merged 1 commit into
mainfrom
fix/esm-require

Conversation

@donnes

@donnes donnes commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Problem

The published CLI is an ESM bundle, so every require() throws Dynamic require of "fs" is not supported when run under Node (npx, npm -g). In practice:

  • sync → Export crashed whenever it had to back up an existing config dir.
  • Every error-trace path crashed while reporting the original error.
  • paths.getRepoRoot() swallowed the failure and fell back to the package's own install dir, so git commands (push, pull, status) ran against the wrong directory.

Codex sync also symlinked all of ~/.codex into the repo, which tracked runtime data like auth.json, sessions and logs.

Fix

  • Replace every dynamic require with static imports, and enable Biome's noCommonJs rule so it can't come back.
  • Write a Codex .gitignore that tracks only AGENTS.md, config.toml, prompts/, rules/ and skills.

Verification

  • Bundled the Amp adapter with tsup and ran export over an existing dir under Node 22: before → Dynamic require of "fs" is not supported; after → linked with a .backup.
  • noCommonJs reports the old code and passes on the new.
  • check:lint, check:types, build and test all pass; the built bundle has no __require( calls.

🤖 Generated with Claude Code

The published CLI is an ESM bundle, so require() throws "Dynamic require
of ... is not supported" under Node (npx, npm -g). This broke exporting
over an existing config dir, every error-trace path, and made git
commands silently fall back to the package install dir instead of the
configured repo. Use static imports everywhere and ban CommonJS via lint.

Also stop syncing Codex runtime data (auth.json, sessions, logs) by
writing a .gitignore that only tracks Codex config.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@donnes
donnes merged commit 50cfbfc into main Oct 22, 2026
1 check passed
@donnes
donnes deleted the fix/esm-require branch October 22, 2026 07:35
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.

1 participant