Skip to content

Conversation

@heathdutton
Copy link

@heathdutton heathdutton commented Dec 25, 2025

When a main entry point contains ESM syntax but is in a package with "type": "commonjs" in package.json, the module would silently exit with code 0 without executing or showing any error. This happened because the CJS loader detected ESM syntax, attempted to defer to ESM loading, but the async execution never completed before the process exited.

This change throws ERR_REQUIRE_ESM for main modules with ESM syntax in explicitly CommonJS-typed packages, providing a clear error message instead of silent failure.

Fixes: #61104

When a main entry point contains ESM syntax but is in a package with
"type": "commonjs" in package.json, the module would silently exit
with code 0 without executing or showing any error. This happened
because the CJS loader detected ESM syntax, attempted to defer to
ESM loading, but the async execution never completed before the
process exited.

This change throws ERR_REQUIRE_ESM for main modules with ESM syntax
in explicitly CommonJS-typed packages, providing a clear error message
instead of silent failure.

Fixes: nodejs#61104
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With "type": "commonjs", #!/usr/bin/env node file does not execute but returns success and no error messages when the file is ESM

2 participants