Skip to content

fix: copy yargs/yargs entrypoint file yargs to yargs.cjs#2514

Merged
shadowspawn merged 8 commits into
yargs:17.x.xfrom
shadowspawn:release-v17.7.3
Jun 12, 2026
Merged

fix: copy yargs/yargs entrypoint file yargs to yargs.cjs#2514
shadowspawn merged 8 commits into
yargs:17.x.xfrom
shadowspawn:release-v17.7.3

Conversation

@shadowspawn

@shadowspawn shadowspawn commented Feb 28, 2026

Copy link
Copy Markdown
Member

Copy yargs/yargs entrypoint file from extension-less yargs to yargs.cjs (for compatibility with Node.js 25.7 and Node.js 26). Anything understanding "exports" will now use yargs.cjs for require('yargs/yargs').

Mostly revert #1747 (but do not delete yargs file).

Fixes #2509

Branch 17.x.x created with

git checkout v17.7.2 
git checkout -b 17.x.x  

Started work with a usable local install created using Node.js 18 and dependencies from around v17.7.2 release using idea from #2408 (comment)

git checkout v17.7.2
rm -rf node_modules package-lock.json
npm --before 2023-04-27 install

Lint for newly noticed file yargs.cjs fixed with

npm run fix

Tests run locally with Node.js 12, 14, 16, 18, 24, 25.7.

require('yargs/yargs') works with Node.js 12, 14, 16, 18, 24, 25.7 with following test file.

const yargsFactory = require('yargs/yargs');

const yargs = yargsFactory(process.argv.slice(2))
  .help()
  .strict();

const argv = yargs.parse();
console.log(argv);

Phase 2.

Get builds working in CI.

  • added tslib and pinned @types/node to get typescript and rollup happy. (After some experimentation.)

Get require('yargs/yargs') working with node 12 before 12.17.0. Conditional exports were not implemented or not turned on or not full working before 12.17.0, and hence the extension-less yargs needed so early node 12 finds a file for yargs/yargs without using "exports". (I had worked that out at one stage, but forgotten!)

  • added back extension-less yargs file for early node 12 (and other old environments before "exports".)

…ess yargs to yargs.cjs (for compatibility with Node.js 25.7)
@shadowspawn shadowspawn changed the title fix: rename yargs/yargs entrypoint file yargs to yards.cjs fix: rename yargs/yargs entrypoint file yargs to yargs.cjs Feb 28, 2026
@shadowspawn shadowspawn changed the title fix: rename yargs/yargs entrypoint file yargs to yargs.cjs fix: copy yargs/yargs entrypoint file yargs to yargs.cjs Mar 2, 2026
@shadowspawn
shadowspawn marked this pull request as ready for review March 2, 2026 06:45
@shadowspawn

Copy link
Copy Markdown
Member Author

A possible replacement for the extension-less yargs file for environments that understand conditional exports.

Not sure how hard it would be to do a 17.7.3 @bcoe , and not sure if Node.js will revert the change in behaviour (nodejs/node#61971).

I have NOT bumped version number as I thought that might be part of release process.

@shadowspawn

Copy link
Copy Markdown
Member Author

node PR opened and being discussed: nodejs/node#62083

@remcohaszing remcohaszing mentioned this pull request Mar 8, 2026
6 tasks
Comment thread yargs Outdated
@jkowalleck

jkowalleck commented May 8, 2026

Copy link
Copy Markdown

node PR opened and being discussed: nodejs/node#62083

Node 26 was released recently, and regardless of how nodejs/node#62083 ultimately landed, yargs 17.7.2 (and likely yargs 16.x as well) currently fail on Node 26.

Thanks a lot for championing the fix, @shadowspawn 🙌

@bcoe — could this PR move forward?

@shadowspawn shadowspawn linked an issue May 9, 2026 that may be closed by this pull request
andersk added a commit to andersk/micromark that referenced this pull request May 16, 2026
Node 25.7.0 broke extensionless CJS scripts in "type": "module"
packages, such as yargs/yargs in yargs 17.x imported by c8; this
behavior was temporarily rolled back in Node 25.8.1 but is now
restored in 26.0.0 and future versions.  Until either yargs releases a
backported fix for yargs 17.x, or c8 fixes its import statement, or c8
upgrades to yargs 18.x (all three of those efforts have been stalled
for months), we need to work around this with an override.

yargs/yargs#2509
yargs/yargs#2514
bcoe/c8#582
bcoe/c8#581
bcoe/c8#578

Signed-off-by: Anders Kaseorg <[email protected]>
andersk added a commit to andersk/micromark that referenced this pull request May 16, 2026
Node 25.7.0 broke extensionless CJS scripts in "type": "module"
packages, such as yargs/yargs in yargs 17.x imported by c8; this
behavior was temporarily rolled back in Node 25.8.1 but is now
restored in 26.0.0 and future versions.  Until either yargs releases a
backported fix for yargs 17.x, or c8 fixes its import statement, or c8
upgrades to yargs 18.x (all three of those efforts have been stalled
for months), we need to work around this with an override.

yargs/yargs#2509
yargs/yargs#2514
bcoe/c8#582
bcoe/c8#581
bcoe/c8#578

Signed-off-by: Anders Kaseorg <[email protected]>
andersk added a commit to andersk/micromark that referenced this pull request May 20, 2026
Node 25.7.0 broke extensionless CJS scripts in "type": "module"
packages, such as yargs/yargs in yargs 17.x imported by c8; this
behavior was temporarily rolled back in Node 25.8.1 but is now
restored in 26.0.0 and future versions.  Until either yargs releases a
backported fix for yargs 17.x, or c8 fixes its import statement, or c8
upgrades to yargs 18.x (all three of those efforts have been stalled
for months), we need to work around this with an override.

yargs/yargs#2509
yargs/yargs#2514
bcoe/c8#582
bcoe/c8#581
bcoe/c8#578

Signed-off-by: Anders Kaseorg <[email protected]>
andersk added a commit to andersk/micromark that referenced this pull request May 20, 2026
Node 25.7.0 broke extensionless CJS scripts in "type": "module"
packages, such as yargs/yargs in yargs 17.x imported by c8; this
behavior was temporarily rolled back in Node 25.8.1 but is now
restored in 26.0.0 and future versions.  Until either yargs releases a
backported fix for yargs 17.x, or c8 fixes its import statement, or c8
upgrades to yargs 18.x (all three of those efforts have been stalled
for months), we need to work around this with an override.

yargs/yargs#2509
yargs/yargs#2514
bcoe/c8#582
bcoe/c8#581
bcoe/c8#578

Signed-off-by: Anders Kaseorg <[email protected]>

@wesleytodd wesleytodd left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just hit this via c8. Anything left to do to get this merged/released? Happy to help if I can, but I think this change looks good to me as is. Especially since it looks like Node.js is committed to this direction for extention-less files, so it looks like this is required for yargs@17 to support 26.

@wesleytodd wesleytodd mentioned this pull request May 22, 2026
2 tasks
@wesleytodd

Copy link
Copy Markdown

nodejs/citgm#1106

@shadowspawn

Copy link
Copy Markdown
Member Author

(Thanks for the reviews.)

@andersk

andersk commented Jun 3, 2026

Copy link
Copy Markdown

It’s clear from Node maintainers’ comments that the Node 25.8.0 behavior is intentionally here to stay in Node ≥ 26 (despite being temporarily reverted in 25.8.1 for the 25.x branch only). yargs/yargs in yargs 17.7.2 will remain broken.

The only way to avoid regressing this significant chunk of the ecosystem is to patch this in new releases of yargs 16 and 17. @bcoe can this be merged and released? Thanks!

@jsumners-nr

Copy link
Copy Markdown

👋 when might this get released?

@shadowspawn

Copy link
Copy Markdown
Member Author

I will work towards a release this month.

@shadowspawn shadowspawn self-assigned this Jun 6, 2026
@jsumners-nr

Copy link
Copy Markdown

I will work towards a release this month.

Looking forward to it. Thank you.

@shadowspawn

Copy link
Copy Markdown
Member Author

Wry amusement, tests currently broken on Node.js 26 because of mocha and c8 dependencies on old yargs.

@shadowspawn
shadowspawn merged commit c7597e3 into yargs:17.x.x Jun 12, 2026
10 checks passed
@shadowspawn

Copy link
Copy Markdown
Member Author

Prerelease 17.7.3-candidate.0 published with tag next-17.

If you are interested, please give it a try with your project with Node.js 26. Give this a thumbs up or leave a comment for success, and a comment with details if you have problems.

@shadowspawn
shadowspawn deleted the release-v17.7.3 branch June 12, 2026 03:22
andersk added a commit to andersk/micromark that referenced this pull request Jun 12, 2026
Node 25.7.0 broke extensionless CJS scripts in "type": "module"
packages, such as yargs/yargs in yargs 17.x imported by c8; this
behavior was temporarily rolled back in Node 25.8.1 but is now
restored in 26.0.0 and future versions.  Until either yargs releases a
backported fix for yargs 17.x, or c8 fixes its import statement, or c8
upgrades to yargs 18.x (all three of those efforts have been stalled
for months), we need to work around this with an override.

yargs/yargs#2509
yargs/yargs#2514
bcoe/c8#582
bcoe/c8#581
bcoe/c8#578

Signed-off-by: Anders Kaseorg <[email protected]>
@jsumners-nr

Copy link
Copy Markdown

Prerelease 17.7.3-candidate.0 published with tag next-17.

If you are interested, please give it a try with your project with Node.js 26. Give this a thumbs up or leave a comment for success, and a comment with details if you have problems.

Unfortunately, we are not able to try it because the issue is in transitive dependencies.

@shadowspawn

Copy link
Copy Markdown
Member Author

clavery added a commit to SalesforceCommerceCloud/b2c-developer-tooling that referenced this pull request Jun 15, 2026
…ha 11 / c8 / yargs) (#499)

* @W-22850150 chore: support Node 26 in CI and modernize test harness (mocha 11 / c8 / yargs)

Add Node 26 to the CI test matrix and modernize the mocha/c8/yargs
toolchain so the suite is green on Node 22, 24, and 26.

CI matrix
- ci.yml: add 26.x to the Linux matrix and the (continue-on-error)
  Windows matrix; document why Node 26 floats on Windows.

mocha 10 -> 11 (catalog bump in pnpm-workspace.yaml)
- Bumping mocha drops the deprecated transitive yargs 16 that mocha 10
  dragged into the test tree (the harness now only pulls yargs 17).
- mocha 11 loads test files via native ESM import() instead of CJS
  require(), which surfaced two issues, both fixed here:

  1. applicationinsights default-import broke. The legacy CommonJS
     `applicationinsights` package has no synthesized default export
     under the native-ESM (tsx) loader, so `import appInsights from
     'applicationinsights'` resolved to `undefined` and the whole
     telemetry suite (69 tests) failed. Switched the SDK source and
     test to a namespace import (`import * as appInsights`), which
     resolves correctly under mocha, tsx, and the production ESM build.
     The 3 tests that spied the TelemetryClient constructor (a frozen,
     non-configurable ESM namespace binding) now spy the SDK's own
     `Telemetry.prototype.createClient` seam and assert the constructed
     client's resolved instrumentationKey instead.

  2. c8/V8 coverage double-counting. `--import tsx` registers BOTH a
     CJS require hook and an ESM load hook, so modules reachable through
     both interop paths were emitted by V8 as two scripts for the same
     URL; c8 merges by URL and summed their function/branch ranges,
     inflating the function denominator (1185 -> 3069) and dropping
     reported coverage ~10 points even though all tests passed. Switched
     every package's mocharc (and the CLI e2e scripts) to the ESM-only
     hook `import=tsx/esm`, which loads each source exactly once and
     restores coverage to the pre-bump baseline. Thresholds unchanged.

yargs / Node 26
- On Node 26, c8 crashed at startup ("require is not defined in ES
  module scope") because it does `require('yargs/yargs')` and yargs
  17.7.2's `require` export condition points at an extensionless file
  containing raw CommonJS; Node 26 now parses extensionless files in a
  type:module package as ESM. Applied a pnpm patch to yargs 17.7.2 that
  faithfully reproduces the merged upstream fix (yargs/yargs#2514): add
  a real `yargs.cjs`, repoint `exports["./yargs"].require` to it, and
  reduce the extensionless `yargs` to a re-export. Avoids pinning the
  17.7.3 prerelease while keeping the trusted 17.7.2 in the tree.

hygiene
- gitignore test-results.json in the mrt-* packages (CI artifact, like
  the other packages already do).

Verified: full test:ci green for all packages on Node 24.14 and 26.3.0
(tests pass + coverage thresholds met); lint, typecheck, format, and
frozen-lockfile install all clean.

* @W-22850150 docs: document the temporary yargs Node 26 patch in patches/README.md

* @W-22850150 ci: bypass coverage gate on Windows for SDK and MCP

The tsx ESM loader (import=tsx/esm) collects unreliable V8 coverage on
Windows: source files are mis-attributed (distinct file:// URL
casing/format vs. the Linux paths c8 remaps against), so SDK reported
0% and MCP 90.87% on the Windows runner even though every test passed.
This regressed the (continue-on-error) test-windows job.

Follow the existing CLI pattern: add a `test:ci:win` script
(c8 --check-coverage=false) to the SDK and MCP packages and use it in
the Windows CI steps. Coverage thresholds are still enforced on Linux,
where attribution is accurate; coverage is still generated and uploaded
on Windows for inspection.
@jsumners-nr

Copy link
Copy Markdown

Awesome! Thank you for the finalized release.

mureinik added a commit to mureinik/node-libpq that referenced this pull request Jul 14, 2026
Follow up on 59a1c9a.
Using `[email protected]` allows us to use a unified `yargs` version for all
supproted Node.js versions instead of having a workaround for Node.js 26 (and
newer).
See yargs/yargs#2514 for details on the `yargs` fix.

This approach has two advantages:
- It simplifies the build process by having a unified approach for every Node.js
  version
- It (moderately) speeds up the Node.js 26 CI, as it can now use a
  straightforward `npm ci`, and no longer needs to perform package resolution
  with `npm install`.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node.js v25.7 and 26 breaks yargs v16 and v17

6 participants