我有一个使用 webpack、eslint 的项目。通过 webpack.config 我设置解析 index
和 Index
文件。一切正常,除了 eslint 抛出错误 import/no-unresolved
和 import/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/