Skip to content

Improve the ERR_AMBIGUOUS_MODULE_SYNTAX error message #60322

@avivkeller

Description

@avivkeller
module.exports;

await 1;

The above code snippet causes an ERR_AMBIGUOUS_MODULE_SYNTAX error, since module.exports cannot be used (CJS) in an ESM file. However, the error logged to the console, shown below, incorrectly assumes the error stems from the use of a require()

ReferenceError: Cannot determine intended module format because both require() and top-level await are present. If the code is intended to be CommonJS, wrap await in an async function. If the code is intended to be an ES module, replace require() with import.

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.good first issueIssues that are suitable for first-time contributors.moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions