Skip to content

Conversation

@Divya9877
Copy link

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.

@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. needs-ci PRs that need a full CI run. labels Dec 5, 2025
@Divya9877
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

errors Issues and PRs related to JavaScript errors originated in Node.js core. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants