Skip to content

fix: CommonJS build fails on import.meta in versionUtils - #47

Merged
mattpodwysocki merged 3 commits into
mainfrom
fix/cjs-import-meta
Oct 26, 2026
Merged

mattpodwysocki merged 3 commits into
mainfrom
fix/cjs-import-meta

Conversation

@mattpodwysocki

Copy link
Copy Markdown
Contributor

The CommonJS build was broken on main: require('@mapbox/mcp-docs-server/tools') (and /resources, /utils) threw SyntaxError: Cannot use 'import.meta' outside a module. src/utils/versionUtils.ts uses import.meta.url, and tshy compiled it into dist/commonjs as is.

The fix mirrors mcp-server's src/utils/versionUtils-cjs.cts: tshy swaps in versionUtils-cjs.cts for the CommonJS build, and it reads version.json from __dirname. The ESM build is unchanged. hosted-mcp-server loads the ESM build, so it was never affected.

Testing

  • Clean build of origin/main in a fresh worktree: require of /tools and /utils throws the import.meta error
  • Same clean build with this change: /tools (3 exports), /resources and /utils all load via require, and getVersionInfo() returns 0.3.1 from both the CJS and ESM builds
  • npm test: 85 passing; lint, format and spellcheck clean

Heads up for local builds: a leftover .tshy-build/ from an interrupted build makes tsc skip re-emitting, so a stale dist can hide this either way. Delete it (it's gitignored) before checking.

🤖 Generated with Claude Code

Adds versionUtils-cjs.cts, which tshy uses for dist/commonjs in place of
versionUtils.ts, reading version.json from __dirname. Same approach as
mcp-server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattpodwysocki mattpodwysocki added the enhancement New feature or request label Oct 21, 2026
@mattpodwysocki
mattpodwysocki requested a review from a team as a code owner October 21, 2026 23:13
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ctufts
ctufts previously approved these changes Oct 23, 2026
@mattpodwysocki
mattpodwysocki merged commit 76c1dc9 into main Oct 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants