执行eslint --init 报错
安装了最新版本的eslint,执行npx eslint --init时报错
Oops! Something went wrong! :(
ESLint: 8.3.0
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: E:\myself\webpack\webpack-test\node_modules\@eslint\eslintrc\universal.js
require() of ES modules is not supported.
require() of E:\myself\webpack\webpack-test\node_modules\@eslint\eslintrc\universal.js from E:\myself\webpack\webpack-test\node_modules\eslint\lib\linter\linter.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename universal.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from E:\myself\webpack\webpack-test\node_modules\@eslint\eslintrc\package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:13)
at Module.load (internal/modules/cjs/loader.js:1001:32)
at Function.Module._load (internal/modules/cjs/loader.js:900:14)
at Module.require (internal/modules/cjs/loader.js:1043:19)
at require (E:\myself\webpack\webpack-test\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
at Object.<anonymous> (E:\myself\webpack\webpack-test\node_modules\eslint\lib\linter\linter.js:27:9)
at Module._compile (E:\myself\webpack\webpack-test\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
at Module.load (internal/modules/cjs/loader.js:1001:32)
at Function.Module._load (internal/modules/cjs/loader.js:900:14)
根据官网(https://eslint.org/docs/user-guide/getting-started)介绍,node版本需要^12.22.0, ^14.17.0, or >=16.0.0才行,而我使用的是12.16.0,升级到14.17.0后完美解决