Skip to content

Fix import statement for Yargs module#581

Open
coderaiser wants to merge 1 commit into
bcoe:mainfrom
coderaiser:patch-2
Open

Fix import statement for Yargs module#581
coderaiser wants to merge 1 commit into
bcoe:mainfrom
coderaiser:patch-2

Conversation

@coderaiser
Copy link
Copy Markdown
Contributor

yargs is ESM, and this file is CommonJS, this is no longer works in node v25

> c8 tape 'test/**/*.js'
file:///Users/coderaiser/@cloudcmd/fileop/node_modules/yargs/yargs:3
const {applyExtends, cjsPlatformShim, Parser, Yargs, processArgv} = require('./build/index.cjs')
                                                                    ^

ReferenceError: require is not defined in ES module scope, you can use import instead
    at file:///Users/coderaiser/@cloudcmd/fileop/node_modules/yargs/yargs:3:69
    at ModuleJobSync.runSync (node:internal/modules/esm/module_job:534:37)

Checklist
  • npm test, tests passing
  • npm run test:snap (to update the snapshot)
  • tests and/or benchmarks are included
  • documentation is changed or added

`yargs` is ESM, and this file is CommonJS, this is no longer works in node v25
@bricss
Copy link
Copy Markdown

bricss commented Mar 12, 2026

The issue with the import statement has been fixed in Node 25.8.1, and everything works ⚙️ as before ⏮️

@andersk
Copy link
Copy Markdown

andersk commented May 16, 2026

@bricss That Node 25.8.1 change was reverted in 26.0.0 (nodejs/node@0c08835).

$ npx c8 --help
Need to install the following packages:
c8@11.0.0
Ok to proceed? (y) y
file:///home/anders/.npm/_npx/ce601f5be3f19082/node_modules/yargs/yargs:3
const {applyExtends, cjsPlatformShim, Parser, Yargs, processArgv} = require('./build/index.cjs')
                                                                    ^

ReferenceError: require is not defined in ES module scope, you can use import instead
    at file:///home/anders/.npm/_npx/ce601f5be3f19082/node_modules/yargs/yargs:3:69
    at ModuleJobSync.runSync (node:internal/modules/esm/module_job:543:37)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:353:47)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1675:24)
    at Module._compile (node:internal/modules/cjs/loader:1838:5)
    at Object..js (node:internal/modules/cjs/loader:1996:10)
    at Module.load (node:internal/modules/cjs/loader:1579:32)
    at Module._load (node:internal/modules/cjs/loader:1381:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
    at Module.require (node:internal/modules/cjs/loader:1602:12)

Node.js v26.1.0

Please merge this one-line fix, it really is required.

@bricss
Copy link
Copy Markdown

bricss commented May 16, 2026

@andersk True story, you can use this yargs/yargs#2509 (comment) trick 🎩 to make it work ⚙️ for now.

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 <andersk@mit.edu>
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 <andersk@mit.edu>
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 <andersk@mit.edu>
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 <andersk@mit.edu>
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.

3 participants