Skip to content

fix: add .js extensions to relative imports for ESM compatibility#13

Merged
tnkshuuhei merged 1 commit intomainfrom
fix/esm-import-extensions
Mar 13, 2026
Merged

fix: add .js extensions to relative imports for ESM compatibility#13
tnkshuuhei merged 1 commit intomainfrom
fix/esm-import-extensions

Conversation

@tnkshuuhei
Copy link
Member

Summary

  • Add explicit .js file extensions to all relative import/export statements in source TypeScript files
  • Update bundle-content.ts generated code templates to include .js extensions
  • This ensures the compiled dist/ output works correctly as an ES module package in Node.js environments (Next.js, Mastra)

Problem

The TypeScript compiler (tsc) preserves bare module specifiers (e.g., from "./types") verbatim in compiled output. Since this package uses "type": "module", Node.js ESM resolution requires explicit file extensions (from "./types.js"). Without them, module resolution fails in strict ESM environments.

Currently, the muse project works around this with a patch file (patches/@beaconlabs-io%2Fevidence@1.1.3.patch). This fix addresses the root cause so the patch can be removed.

Changes

File Change
src/index.ts ./types./types.js, ./content./content/index.js
src/content/index.ts ../types../types.js, ./evidence./evidence.js, ./deployments./deployments.js
scripts/bundle-content.ts Generated import templates: ../types../types.js (2 places)

Test plan

  • bun run build completes successfully
  • dist/index.js contains from "./types.js" and from "./content/index.js"
  • dist/content/index.js contains .js extensions on all relative imports
  • After publish, remove patch in muse/ and verify bun dev / bun run build work

🤖 Generated with Claude Code

TypeScript compiler preserves bare module specifiers in compiled output,
which breaks ESM resolution in Node.js environments (Next.js, Mastra).
Add explicit .js extensions to all relative imports so the compiled
dist/ output works correctly as an ES module package.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tnkshuuhei tnkshuuhei merged commit 952004d into main Mar 13, 2026
2 checks passed
@github-actions github-actions bot mentioned this pull request Mar 13, 2026
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