Skip to content

module: warn on invalid package.json type field - #60180

Open
Shuklax wants to merge 2 commits into
nodejs:mainfrom
Shuklax:module-validate-type-field
Open

module: warn on invalid package.json type field#60180
Shuklax wants to merge 2 commits into
nodejs:mainfrom
Shuklax:module-validate-type-field

Conversation

@Shuklax

@Shuklax Shuklax commented Oct 9, 2025

Copy link
Copy Markdown

Add validation to warn users when the "type" field in package.json contains an invalid value. Previously, values like "CommonJS" (wrong case) would silently fall back to typeless behavior. Now a clear warning message is displayed indicating the expected values are "commonjs" or "module".

Fixes: #60085

Add validation to warn users when the "type" field in package.json
contains an invalid value. Previously, values like "CommonJS" (wrong
case) would silently fall back to typeless behavior. Now a clear
warning message is displayed indicating the expected values are
"commonjs" or "module".

Fixes: nodejs#60085
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 9, 2025

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tests look good to me, i'll let someone else review the C++

@codecov

codecov Bot commented Oct 9, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.56%. Comparing base (7c85aa5) to head (e6223ee).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60180      +/-   ##
==========================================
+ Coverage   88.52%   88.56%   +0.03%     
==========================================
  Files         703      704       +1     
  Lines      207825   208092     +267     
  Branches    40003    40012       +9     
==========================================
+ Hits       183976   184294     +318     
+ Misses      15862    15811      -51     
  Partials     7987     7987              
Files with missing lines Coverage Δ
src/node_modules.cc 76.49% <100.00%> (+0.27%) ⬆️

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

Comment thread src/node_modules.cc Outdated
}

if (field_value != "commonjs" && field_value != "module") {
fprintf(stderr,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be using the usual machinery (process.emitWarning() in JS, or ProcessEmitWarning() in C++) to emit warning so that it can be suppressed with NODE_NO_WARNINGS=1 etc. or captured through event listeners by users.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done! Changed to use ProcessEmitWarning() instead of fprintf(). Let me know if the implementation looks correct.

Comment thread src/node_modules.cc Outdated
if (package_json == nullptr) {
return;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
}
}

Comment thread test/parallel/test-find-package-json.js Outdated

});

describe('package.json type field validation', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a new test file instead of appending it to the same test file? See

In principle, when adding a new test, it should be placed in a new file.
Unless there is strong motivation to do so, refrain from appending
new test cases to an existing file. Similar to the reproductions we ask

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done! I've added a new test file.

@mertcanaltin

Copy link
Copy Markdown
Member

lint errors in some lines
you can make format-cpp command

@Shuklax

Shuklax commented Jan 15, 2026

Copy link
Copy Markdown
Author

@ljharb, @mertcanaltin I have done the necessary changes, please have a look at my PR as per your convenience.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

@github-actions github-actions Bot added the stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure. label Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

@github-actions github-actions Bot closed this Aug 27, 2026
@ljharb

ljharb commented Aug 28, 2026

Copy link
Copy Markdown
Member

i think this should land once somebody reviews the C++

@ljharb ljharb reopened this Aug 28, 2026
@ljharb ljharb removed the stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure. label Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn when package.json contains an invalid "type" value

5 participants