微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

npx eslint --init 报错

执行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后完美解决

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐