Skip to content

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

Open
leno23 wants to merge 2 commits 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 2 commits into
validatorjs:masterfrom
leno23:fix/es-import-extensions-2528

Conversation

@leno23

@leno23 leno23 commented May 25, 2026

Copy link
Copy Markdown

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

@leno23 leno23 force-pushed the fix/es-import-extensions-2528 branch from c37f1c5 to 41c5a80 Compare May 26, 2026 05:06
@leno23

leno23 commented Jun 8, 2026

Copy link
Copy Markdown
Author

Addressed the Node.js 8 CI failure in commit da8cfac. The build script no longer relies on fs.Dirent / withFileTypes, which Node 8 does not support; it now walks names from fs.readdirSync and checks directories with fs.statSync.

Local verification:

  • node -c scripts/add-es-import-extensions.js

The shallow checkout did not include the generated es directory, so the full build remains covered by GitHub CI.

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7fdc788) to head (da8cfac).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2720   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2587      2587           
  Branches       656       656           
=========================================
  Hits          2587      2587           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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