Skip to content

[v25.7] yargs v17 compatibility issue #61971

@liuxingbaoyu

Description

@liuxingbaoyu

Version

v25.7.0

Platform

Microsoft Windows NT 10.0.26200.0 x64

Subsystem

No response

What steps will reproduce the bug?

  1. npm i yargs@17.7.2
  2. "require('yargs/yargs')" > 1.cjs
  3. node 1.cjs

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

no errors

What do you see instead?

file:///F:/node-yargs/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:///F:/node-yargs/node_modules/yargs/yargs:3:69
    at ModuleJobSync.runSync (node:internal/modules/esm/module_job:534:37)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:366:47)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1628:24)
    at Module._compile (node:internal/modules/cjs/loader:1793:5)
    at Object..js (node:internal/modules/cjs/loader:1951:10)
    at Module.load (node:internal/modules/cjs/loader:1532:32)
    at Module._load (node:internal/modules/cjs/loader:1334:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
    at Module.require (node:internal/modules/cjs/loader:1555:12)

Node.js v25.7.

Additional information

I'm not sure if this is a Node.js issue, because yargs uses a file without an extension as the entry point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    loadersIssues and PRs related to ES module loaders

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions