errors: add ERR_AMBIGUOUS_MODULE_SYNTAX message
Summary
Adds an error message for ERR_AMBIGUOUS_MODULE_SYNTAX, which is used when a file mixes CommonJS and ES Module syntax.
Changes
- Registered ERR_AMBIGUOUS_MODULE_SYNTAX in lib/internal/errors.js with a clear explanatory message.
Why
This improves developer experience by explaining that the file mixes CommonJS (require, module.exports) with ES Module features (import, export, top-level await) and suggests using a single module system consistently.
Hi maintainers 👋,
This PR adds a test case for the new ERR_AMBIGUOUS_MODULE_SYNTAX error.
🔹 What I added
A new test at: test/es-module/test-ambiguous-module-syntax.js
A new fixture at: test/fixtures/es-modules/ambiguous-mixed-syntax.js
🔹 What the test does
Uses the mixed-syntax fixture to simulate ambiguous ESM/CJS usage.
Runs the module through Node.
Asserts that Node throws the expected error code: ERR_AMBIGUOUS_MODULE_SYNTAX.
Ensures the new error message is correctly triggered and validated.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 88.52%. Comparing base (c6316f9) to head (4b35ee1).
:warning: Report is 562 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #60968 +/- ##
==========================================
+ Coverage 88.45% 88.52% +0.06%
==========================================
Files 703 703
Lines 207546 208437 +891
Branches 40011 40200 +189
==========================================
+ Hits 183591 184524 +933
+ Misses 15949 15903 -46
- Partials 8006 8010 +4
| Files with missing lines | Coverage Δ | |
|---|---|---|
| lib/internal/errors.js | 97.52% <100.00%> (+<0.01%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Tests are not passing, and the linked issue was closed as resolved. Closing for now, thanks for the PR.