Skip to content

fix: add .js extensions to es build for Node ESM#2720

Open
leno23 wants to merge 1 commit into
validatorjs:masterfrom
leno23:fix/es-import-extensions-2528
Open

fix: add .js extensions to es build for Node ESM#2720
leno23 wants to merge 1 commit into
validatorjs:masterfrom
leno23:fix/es-import-extensions-2528

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 25, 2026

Summary

Fixes #2528

Node ESM requires explicit .js extensions on relative imports. The es/ build output currently emits imports like from './util/assertString' without extensions, causing ERR_MODULE_NOT_FOUND when importing individual validators in Node.

This adds a post-build step (scripts/add-es-import-extensions.js) that runs after babel in build:es and appends .js to relative import/export paths in the generated es/ tree.

Also updates README examples to use the correct .js paths for both CommonJS and ESM.

Test plan

  • npm run build:es completes successfully
  • Node ESM import of ./es/lib/isEmail.js works
  • npm test — 318 tests passing

Made with Cursor

Closes validatorjs#2528

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Documentation Issue: Incorrect ES Import Path

1 participant