【发布时间】:2021-01-16 14:21:31
【问题描述】:
我不断收到 eslint 错误 import/no-unresolved 并且不确定如何修复它。我知道这与 babel 有关,但我不确定如何让 babel 和 eslint 玩得很好。
我的 babel.config.js 文件:
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-react'],
plugins: [
'babel-plugin-macros',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties',
{
loose: true,
},
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true,
},
],
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true,
},
],
[
'@babel/plugin-transform-regenerator',
{
async: false,
},
],
],
};
…和我的 .eslintrc.js 文件
module.exports = {
parser: 'babel-eslint',
extends: 'airbnb',
env: {
browser: true,
node: true,
jest: true,
es6: true,
},
plugins: ['react', 'jsx-a11y'],
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
rules: {
'object-curly-spacing': 2,
'arrow-parens': ['error', 'as-needed'],
'arrow-body-style': [2, 'as-needed'],
'comma-dangle': [2, 'always-multiline'],
'import/imports-first': 0,
'import/newline-after-import': 0,
'import/no-dynamic-require': 0,
'import/no-extraneous-dependencies': 0,
'import/no-named-as-default': 0,
'import/no-unresolved': 2,
'import/prefer-default-export': 0,
indent: [
2,
2,
{
SwitchCase: 1,
},
],
'space-before-function-paren': 0,
'jsx-a11y/aria-props': 2,
'jsx-a11y/heading-has-content': 0,
'jsx-a11y/label-has-associated-control': 2,
'jsx-a11y/mouse-events-have-key-events': 2,
'jsx-a11y/no-autofocus': 0,
'jsx-a11y/role-has-required-aria-props': 2,
'jsx-a11y/role-supports-aria-props': 2,
'max-len': 0,
'newline-per-chained-call': 0,
'no-confusing-arrow': 0,
'no-console': 1,
'no-use-before-define': 0,
'prefer-template': 2,
'class-methods-use-this': 0,
'react/forbid-prop-types': 0,
'react/jsx-first-prop-new-line': [2, 'multiline'],
'react/jsx-filename-extension': 0,
'react/prefer-stateless-function': 0,
'react/jsx-no-target-blank': 0,
'react/require-extension': 0,
'react/prop-types': 0,
'react/self-closing-comp': 0,
'require-yield': 0,
'import/no-webpack-loader-syntax': 0,
semi: ['error', 'always'],
},
settings: {
'import/resolver': {
webpack: {
config: 'config/webpack/development.js',
},
},
},
};
有什么建议吗?
编辑
我已经使用我在这个项目中使用的相同 eslint 设置创建了一个存储库。它显示的错误与我看到的相同。
【问题讨论】:
-
您好 Brandon,可能存在以下情况 - 您尝试从文件系统/模块导入的方式和内容。如果您可以发布出现错误的用法 - 可能会有用。您可以尝试的一件事是在 eslintrc 文件中添加道具以忽略大小写敏感性“规则”:{“import/no-unresolved”:[2,{“caseSensitive”:false}]}
-
添加了显示所有导入的 eslint 错误的屏幕截图。
-
第 1 步:开始将其减少到您的 eslint 可能为 2 或 3 行的位置,但您仍然会遇到错误。然后开始减少你的 babel 配置,直到它只有几行。然后将您的实际测试用例减少到在单个文件上运行该配置。现在,您有一个出色的 Stackoverflow minimal reproducible example,您已经完成了 您 可以做的所有工作,以深入了解可能出现的问题,其他人可以立即为您处理。如果您在形成 MCVE 时还没有找到解决方案。
-
虽然我非常怀疑这是因为您说您希望 ESLint 将您的代码验证为 ecmaVersion
6而不是2018。 6 没有模块支持。
标签: javascript babeljs eslint