下面是JSON:
{
"env": {
"node": true
},
"root": true,
"parser": "@typescript-eslint/parser",
"extends": [
"standard",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:promise/recommended",
"prettier"
],
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module"
},
"plugins": [
"prettier", "@typescript-eslint"
],
"rules": {
"semi": [2, "always"]
}
}接下来是js文件:
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: [
'standard',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:promise/recommended',
'prettier',
],
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
plugins: ['prettier', '@typescript-eslint'],
rules: {
'semi': [2, 'always']
},
env: {
node: true,
},
};不知道是什么导致了这个问题。
如果我注释js文件的内容并离开json,然后运行npx eslint src/test.ts,我得到以下结果:
Oops! Something went wrong! :(
ESLint: 7.32.0
ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".
(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/Users/Albert/Documents/Projects".)
It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
npm install @typescript-eslint/eslint-plugin@latest --save-dev
The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "../.eslintrc.js".
If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.为什么它要在'Projects‘dir中寻找插件?
我尝试了提出的解决方案,但没有奏效。
发布于 2022-02-26 13:00:03
看起来,项目文件夹中有一个ESLint配置文件,它位于实际项目文件夹的目录结构上。
在文件夹中运行ESLint时,ESLint首先查找该文件夹中的配置文件。然后,它在父文件夹中查找--如果那里有一个配置文件,则将其与初始配置文件合并。ESLint一直在目录结构上,并合并它找到的每个配置文件,直到它到达根目录为止。
如果要将ESLint限制为项目中的配置文件,请将其添加到eslintrc.js或eslintrc.json文件中:
{
"root": true
}这将使ESLint不再寻找这个之外的配置文件。
无论向哪个文件添加root键,都要删除另一个文件。如果一个文件夹中有多个配置文件,ESLint将只使用一个配置文件(在eslintrc.js和eslintrc.json之间,它将使用前者,因为每种格式都有优先级顺序)。
https://stackoverflow.com/questions/70719874
复制相似问题