Skip to content

module: fix extensionless entry with explicit type=commonjs#61600

Open
inoway46 wants to merge 8 commits intonodejs:mainfrom
inoway46:fix-extensionless-type-commonjs-esm
Open

module: fix extensionless entry with explicit type=commonjs#61600
inoway46 wants to merge 8 commits intonodejs:mainfrom
inoway46:fix-extensionless-type-commonjs-esm

Conversation

@inoway46
Copy link

@inoway46 inoway46 commented Jan 31, 2026

When an extensionless 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 extensionless files skip the .js suffix check in the CJS loader, so the explicit type: commonjs was not being enforced, allowing ESM syntax to be silently delegated to ESM loading which never completed before the process exited.

This change ensures the CJS loader treats extensionless entry points as commonjs when type is explicitly set to "commonjs" in package.json, forcing ESM syntax to surface as a SyntaxError instead of silently exiting.

Fixes: #61104

Related: #61171 (alternative approach)

@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 Jan 31, 2026
@inoway46 inoway46 marked this pull request as ready for review January 31, 2026 15:45
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, a couple of comments, otherwise this looks good.

@inoway46 inoway46 requested a review from joyeecheung February 1, 2026 04:06
@inoway46 inoway46 requested a review from joyeecheung February 1, 2026 17:12
@inoway46 inoway46 requested a review from joyeecheung February 6, 2026 16:17
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 7, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 7, 2026
@nodejs-github-bot
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.74%. Comparing base (f6464c5) to head (601e4c5).
⚠️ Report is 66 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61600      +/-   ##
==========================================
- Coverage   89.76%   89.74%   -0.03%     
==========================================
  Files         673      675       +2     
  Lines      203944   204511     +567     
  Branches    39191    39305     +114     
==========================================
+ Hits       183080   183540     +460     
- Misses      13194    13248      +54     
- Partials     7670     7723      +53     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 98.36% <100.00%> (+0.19%) ⬆️

... and 60 files with indirect coverage changes

🚀 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.

@inoway46
Copy link
Author

inoway46 commented Feb 7, 2026

Thanks for the approval.
I pushed a small lint follow-up: I added require('../common') at the top of test/es-module/test-extensionless-esm-type-commonjs.js to satisfy the required module ordering rules.

I also verified make lint-js locally for the changed JS files.
Could you please rerun CI if needed? Thank you.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 8, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 8, 2026
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 8, 2026
@joyeecheung joyeecheung added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Feb 8, 2026
@joyeecheung
Copy link
Member

@inoway46 Can you squash the commits? I don't think they would pass the test individually.

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

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. 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

6 participants