【问题标题】:How to resolve "import/no-unresolved" in ESLint for import files! for javascript and nodejs?如何在 ESLint 中为导入文件解析“import/no-unresolved”!对于javascript和nodejs?
【发布时间】:2022-01-16 02:22:56
【问题描述】:

这是我的问题

Eslint 找不到文件的位置?

这是错误!

提前感谢您的帮助!

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: javascript node.js babeljs eslint


【解决方案1】:

我遇到了这个问题!

Eslint 找不到文件的位置,因为文件的路径没有完全定义,我们必须在配置文件中指定它们。

引用存在并且有效,问题是 eslint 找不到它。我修复如下!

无法解析模块路径“./Board”。请注意,Board 没有扩展名,这就是问题所在!我们只需要指定 eslint 如何解析扩展,瞧。

我假设 eslint 已安装,但在集成 express node 和 react js 项目时遇到问题

您可以按照步骤使用 eslint 的自动配置,并在安装时配置您的 .eslint.json 文件添加 settings

的描述
"settings": {
"import/resolver": {
  "node": {
    "extensions": [".js", ".jsx"],
    "moduleDirectory": ["node_modules", "src/"]
  }
}

}

.eslintrc.json 完整文件如下:

    {
  "env": {
    "browser": true,
    "es2021": true,
    "node": true
  },
  "extends": ["plugin:import/recommended", "plugin:react/recommended", "standard"],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": ["react"],
  "rules": {
    "semi": [2, "always"],
    "comma-dangle": [
      "error",
      {
        "arrays": "only-multiline",
        "objects": "only-multiline",
        "imports": "only-multiline",
        "exports": "only-multiline",
        "functions": "only-multiline"
      }
    ],
    "space-before-function-paren": 0,
    "spaced-comment": [
      "error",
      "never",
      {
        "line": {
          "markers": ["/"],
          "exceptions": ["-", "+"]
        },
        "block": {
          "markers": ["!", "-", "+"],
          "exceptions": ["*"],
          "balanced": true
        }
      }
    ]
  },
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx"],
        "moduleDirectory": ["node_modules", "src/"]
      }
    }
  }
}

https://eslint.org/docs/user-guide/getting-started

【讨论】:

    猜你喜欢
    • 2019-10-05
    • 2020-11-25
    • 2021-03-13
    • 2021-08-22
    • 2022-06-24
    • 2019-06-21
    • 2018-03-17
    • 2017-11-10
    • 2022-12-03
    相关资源
    最近更新 更多