DEV Community

Cui Mingda
Cui Mingda

Posted on

How to fix import/no-unresolved error while import jsx without extension

在ESLint中设置了eslint-plugin-import扩展

"extends": [
  "plugin:import/recommended",
],
Enter fullscreen mode Exit fullscreen mode

当引入一个React文件的时候会校验失败,引入的逻辑没啥特别的

import App from "./App";
Enter fullscreen mode Exit fullscreen mode

具体触发的规则:

error  Unable to resolve path to module './App'  import/no-unresolved
Enter fullscreen mode Exit fullscreen mode

原因比较明显,因为没有扩展名,并且没有去试着解析jsx,所以只要在设置中加上这个要求就好了。

"eslintConfig": {
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    }
  },
}
Enter fullscreen mode Exit fullscreen mode

References

Top comments (0)