gpt4 book ai didi

javascript - 我如何更改 eslint 解析设置

转载 作者:搜寻专家 更新时间:2023-11-01 05:27:49 34 4
gpt4 key购买 nike

我有一个使用 webpack、eslint 的项目。通过 webpack.config 我设置解析 indexIndex 文件。一切正常,除了 eslint 抛出错误 import/no-unresolvedimport/extensions,它不知道,除了 index,现在它也应该解析 Index 文件(从 ./components 导入索引,其中 ./components 中有文件 Index.jsx)。我的设置如下。

// .eslintrc
{
"extends": "airbnb",
"env": { "browser": true },
"rules": {
"no-restricted-syntax": "off",
"no-continue": "off",
"no-plusplus": "off",
"react/prop-types": "off",
"no-underscore-dangle": "off",
"no-param-reassign": "off",
"class-methods-use-this": "off"
}
}

// package.json
// ...
"devDependencies": {
// ...
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.10.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
// ...
}
// ...

最佳答案

尝试安装 eslint-import-resolver-webpack 并将其添加到您的 .eslintrc:

"settings": {
"import/resolver": "webpack"
}

或者添加将从中解析依赖项的源文件夹;像这样:

settings: {
'import/resolver': {
node: {
paths: [path.resolve(__dirname, 'src')],
},
},
}

解析器文档:https://github.com/benmosher/eslint-plugin-import/blob/master/README.md#resolvers

关于javascript - 我如何更改 eslint 解析设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50041345/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com