Skip to content

Fix ESM bare directory imports causing ERR_UNSUPPORTED_DIR_IMPORT#27

Open
kalahari wants to merge 1 commit intovoyage-ai:mainfrom
kalahari:issue-26-fix-esm-directory-imports
Open

Fix ESM bare directory imports causing ERR_UNSUPPORTED_DIR_IMPORT#27
kalahari wants to merge 1 commit intovoyage-ai:mainfrom
kalahari:issue-26-fix-esm-directory-imports

Conversation

@kalahari
Copy link
Copy Markdown

@kalahari kalahari commented Mar 6, 2026

Summary

  • Fixes the ESM build script (scripts/rename-to-esm-files.js) to resolve bare directory/file imports that lack file extensions
  • Directory imports (e.g. ../api) are rewritten to ../api/index.mjs
  • File imports (e.g. ../Client) are rewritten to ../Client.mjs
  • The existing regex only handled imports already ending in .js, leaving extensionless imports untouched

Fixes #26

Test plan

  • pnpm build succeeds with no bare imports remaining in dist/esm/
  • ESM import works: node -e "import { VoyageAIClient } from 'voyageai'" --input-type=module
  • CJS import still works: node -e "const { VoyageAIClient } = require('voyageai')"
  • pnpm test:unit — all 421 tests pass
  • pnpm run check — no new lint issues introduced

The ESM build rename script only rewrote imports ending with .js to
.mjs, but left bare imports (e.g. "../api", "./tokenizer") untouched.
Node.js ESM does not support directory imports or extensionless imports,
causing ERR_UNSUPPORTED_DIR_IMPORT at runtime.

Add resolution for bare imports: directories get /index.mjs appended,
files get .mjs appended.

Fixes voyage-ai#26
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.

ESM exports broken — bare directory imports in .mjs files cause ERR_UNSUPPORTED_DIR_IMPORT

1 participant