Skip to content

cjs context globals are available unexpected in ESM when using node --eval 'import("pkg")' #57885

@JounQin

Description

@JounQin

Version

v22.13.1

Platform

Linux mightyiam-eslintconfigl-deiiy42chvs 6.1.91-060191-generic #202407021948 SMP PREEMPT_DYNAMIC Tue Jul  2 20:28:47 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

un-ts/eslint-plugin-import-x#296

npm install -D eslint-plugin-import-x@4.10.3

node --eval 'import("eslint-plugin-import-x")'

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

consistently

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

No error

What do you see instead?

node:internal/modules/cjs/loader:1244
  const err = new Error(message);
              ^

Error: Cannot find module '../package.json'
Require stack:
- /tmp/L5XoA9/[eval]
    at Function._resolveFilename (node:internal/modules/cjs/loader:1244:15)
    at Function._load (node:internal/modules/cjs/loader:1070:27)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1335:12)
    at require (node:internal/modules/helpers:136:16)
    at file:///tmp/L5XoA9/node_modules/eslint-plugin-import-x/lib/meta.js:5:34
    at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:436:15) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/tmp/L5XoA9/[eval]' ]
}

Node.js v22.13.1

Additional information

eslint-plugin-import-x is a dual package

Metadata

Metadata

Assignees

No one assigned

    Labels

    moduleIssues and PRs related to the module subsystem.stale

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions