Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: module.exports on CJS modules #57366

Closed
wants to merge 1 commit into from

Conversation

guybedford
Copy link
Contributor

Resolves #57295.

While the special "module.exports" name was defined for exporting from ESM modules for their representation in CommonJS, when writing a CommonJS with a "module.exports" export name will cause a V8 error.

The actual issue here is that we don't check if module.exports is already an export when defining the module wrap exports and as a result it is defined twice causing the failed V8 check.

To avoid unnecessary work, we also update the code path to instead of settin this export and then override it later, just not setting it at all. To avoid unnecessary hasOwnProperty checks, these checks are moved earlier in the sequence as well.

//cc @nodejs/loaders

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Mar 7, 2025
@guybedford guybedford force-pushed the module-exports-error branch from 80e32fb to 7c1bb9b Compare March 7, 2025 21:09
Copy link

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.21%. Comparing base (27f98c3) to head (7c1bb9b).
Report is 16 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #57366   +/-   ##
=======================================
  Coverage   90.20%   90.21%           
=======================================
  Files         630      630           
  Lines      185307   185311    +4     
  Branches    36269    36270    +1     
=======================================
+ Hits       167162   167173   +11     
- Misses      11084    11090    +6     
+ Partials     7061     7048   -13     
Files with missing lines Coverage Δ
lib/internal/modules/esm/translators.js 91.57% <100.00%> (+0.06%) ⬆️

... and 41 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.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 8, 2025
@nodejs-github-bot

This comment was marked as outdated.

@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 8, 2025
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@guybedford
Copy link
Contributor Author

CI seems to be fully passing here except for the ubuntu2204-armv7l runner which seems to have some problems starting up. Unless anyone objects will land anyway tomorrow.

@richardlau
Copy link
Member

CI seems to be fully passing here except for the ubuntu2204-armv7l runner which seems to have some problems starting up. Unless anyone objects will land anyway tomorrow.

They're failing in the fanned job because they succeeded in https://ci.nodejs.org/job/node-test-pull-request/65639/ and the temporary binaries were deleted. Basically https://ci.nodejs.org/job/node-test-pull-request/65639 and https://ci.nodejs.org/job/node-test-pull-request/65640/ raced each other and now the only way to get a clean CI run would be to start a new one (not resume).

guybedford added a commit that referenced this pull request Mar 9, 2025
PR-URL: #57366
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@guybedford
Copy link
Contributor Author

Landed in fbe37d5.

@guybedford guybedford closed this Mar 9, 2025
@guybedford guybedford deleted the module-exports-error branch March 9, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing cjs file with "module.exports" export causes fatal error
6 participants