Description
Environment
Node version: v20.12.0
npm version: 10.8.0
Local ESLint version: v9.2.0
Global ESLint version: n/a
Operating System: macOS
What parser are you using?
Default (Espree)
What did you do?
An empty directory with just this eslint.config.js
:
const js = require("@eslint/js");
module.exports = [
js.configs.recommended,
]
Run the CLI with npx as documented:
$ npx eslint
What did you expect to happen?
The require
/ import
statements resolve. @eslint/js
is installed with ESLint:
Line 72 in 06f1d1c
What actually happened?
Crash:
$ npx eslint
Oops! Something went wrong! :(
ESLint: 9.2.0
Error: Cannot find module '@eslint/js'
Require stack:
- /Users/chainz/tmp/test-eslint/eslint.config.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Module._load (node:internal/modules/cjs/loader:984:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at Object.<anonymous> (/Users/chainz/tmp/test-eslint/eslint.config.js:1:12)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at cjsLoader (node:internal/modules/esm/translators:366:17)
The way ESLint loads the config file means that its import statements aren’t resolved.
(The bug also occurs with ESM config in eslint.config.mjs
, with a slightly different error message: Cannot find package '@eslint/js' imported from /Users/chainz/tmp/test-eslint/eslint.config.mjs
.)
Link to Minimal Reproducible Example
Open https://stackblitz.com/edit/stackblitz-starters-jycfg3?file=eslint.config.js and run npx eslint
:
Participation
- I am willing to submit a pull request for this issue.
Additional comments
It seems that to use flat config, you must install ESLint in the same directory as configuration? If so, that really breaks using tool managers—I found this out when using ESLint under pre-commit, which manages tools in its own directory outside of your project.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status