Skip to content

Conversation

@vivek958
Copy link

@vivek958 vivek958 commented Oct 25, 2025

Description

Fixes #60401

The loadCJSModule function in lib/internal/modules/esm/translators.js was not validating source content before passing it to the native compileFunctionForCJSLoader function. When source was null or undefined, this caused an internal assertion failure instead of throwing a meaningful error.

Changes

  • Added source validation in loadCJSModule to check for null/undefined/empty source
  • Throws ERR_INVALID_RETURN_PROPERTY_VALUE with descriptive message instead of internal assertion

Testing

The validation prevents the internal assertion that was occurring with custom loaders returning null source.

  • Added test file: test/parallel/test-esm-loader-null-source.js
  • Tests verify proper error handling for null/undefined/empty source
  • Tests ensure ERR_INTERNAL_ASSERTION is not thrown

Checklist

  • make -j4 test (UNIX) or vcbuild test (Windows) passes (will be verified by CI)
  • commit message follows commit guidelines

…_ASSERTION in CJS module loading

Fixes: nodejs#60401

The loadCJSModule function was not properly validating source
content before passing it to compileFunctionForCJSLoader, causing internal assertions when source was null or undefined.

This change adds proper source validation and throws a meaningful ERR_INVALID_RETURN_PROPERTY_VALUE error instead of failing with an internal assertion.
@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 Oct 25, 2025
@aduh95
Copy link
Contributor

aduh95 commented Oct 25, 2025

The validation prevents the internal assertion that was occurring with custom loaders returning null source. Not yet tested due to my system limitations.

Could you add a test?

Add test cases to verify that loadCJSModule properly handles
null, undefined, and empty string source values by throwing
ERR_INVALID_RETURN_PROPERTY_VALUE instead of triggering
ERR_INTERNAL_ASSERTION.

Tests three scenarios:
- Custom loader returning null source
- Custom loader returning undefined source  
- Custom loader returning empty string source

Refs: nodejs#60401
@vivek958
Copy link
Author

vivek958 commented Oct 25, 2025

Could you add a test?

done, added test case in second commit to verify the fix works correctly. The test covers null, undefined, and empty string source values to ensure ERR_INVALID_RETURN_PROPERTY_VALUE is thrown instead of ERR_INTERNAL_ASSERTION. @aduh95

@vivek958
Copy link
Author

Friendly ping @nodejs/loaders - would appreciate any feedback when you have time!

vivek958 and others added 2 commits October 30, 2025 01:15
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.58%. Comparing base (ba7cdf4) to head (4d2299a).
⚠️ Report is 39 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60408      +/-   ##
==========================================
+ Coverage   88.56%   88.58%   +0.01%     
==========================================
  Files         704      704              
  Lines      207774   207841      +67     
  Branches    40027    40043      +16     
==========================================
+ Hits       184020   184120     +100     
+ Misses      15800    15765      -35     
- Partials     7954     7956       +2     
Files with missing lines Coverage Δ
lib/internal/modules/esm/translators.js 93.03% <100.00%> (+0.13%) ⬆️

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

@vivek958
Copy link
Author

@aduh95 I've made some changes, checks are needed again

@vivek958 vivek958 requested a review from aduh95 October 31, 2025 12:49
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.

ERR_INTERNAL_ASSERTION

3 participants