fix: copy yargs/yargs entrypoint file yargs to yargs.cjs#2514
Conversation
…ess yargs to yargs.cjs (for compatibility with Node.js 25.7)
|
A possible replacement for the extension-less 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. |
|
node PR opened and being discussed: nodejs/node#62083 |
…mise changes and revert
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? |
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]>
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]>
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]>
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]>
There was a problem hiding this comment.
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.
|
(Thanks for the reviews.) |
|
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).
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! |
|
👋 when might this get released? |
|
I will work towards a release this month. |
Looking forward to it. Thank you. |
… fails for some dependencies on node<18
|
Wry amusement, tests currently broken on Node.js 26 because of mocha and c8 dependencies on old yargs. |
|
Prerelease 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. |
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]>
Unfortunately, we are not able to try it because the issue is in transitive dependencies. |
|
You can potentially use |
…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.
|
Awesome! Thank you for the finalized release. |
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
Copy
yargs/yargsentrypoint file from extension-lessyargstoyargs.cjs(for compatibility with Node.js 25.7 and Node.js 26). Anything understanding"exports"will now useyargs.cjsforrequire('yargs/yargs').Mostly revert #1747 (but do not delete
yargsfile).Fixes #2509
Branch 17.x.x created with
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)
Lint for newly noticed file
yargs.cjsfixed withTests 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.Phase 2.
Get builds working in CI.
tsliband pinned@types/nodeto 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-lessyargsneeded so early node 12 finds a file foryargs/yargswithout using"exports". (I had worked that out at one stage, but forgotten!)yargsfile for early node 12 (and other old environments before"exports".)