【问题标题】:Next import/no-unresolved eslint nextjs module path下一个 import/no-unresolved eslint nextjs 模块路径
【发布时间】:2022-06-24 01:45:56
【问题描述】:

我正在使用下一个模块导入。 尝试像这样导入组件。

import Navbar from '@/components/Navbar/Navbar';

当我运行 npm 时,运行 lint。我收到以下错误。

1:20 Error: Unable to resolve path to module '@/components/Navbar/Navbar'. import/no-unresolved

这是我的 jsconfig.json

  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"],
      "@/components/*": ["components/*"],
      "@/pages/*": ["pages/*"],
      "@/styles/*": ["styles/*"]
    }
  }
}

这是 eslintrc.json

  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 11,
    "sourceType": "module"
  },
  "settings": {
    "react": {
      "version": "detect"
    },
    "import/resolver": {
      "alias": {
        "map": [
          ["@components", "./components/*"],
          ["@images", "./public/*"],
          ["@/pages/*", "pages/*"],
          ["@/styles/*", "styles/*"]
        ],
        "extensions": [".js", ".jsx"]
      }
    }
  },
  "plugins": ["react", "react-hooks", "jest"],
  "rules": {
    "react/jsx-props-no-spreading": 0,
    "react/react-in-jsx-scope": "off",
    "import/extensions": "off",
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], 
    "react/display-name": 1,
    "jest/no-disabled-tests": "warn",
    "jest/no-focused-tests": "error",
    "jest/no-identical-title": "error",
    "jest/prefer-to-have-length": "warn",
    "jest/valid-expect": "error",
    "import/no-unresolved": [2, { "caseSensitive": false }]
  }
}

我从here 和这里here 尝试了许多解决方案。好像没用。

【问题讨论】:

    标签: javascript reactjs next.js eslint


    【解决方案1】:

    关于问题的任何更新?我对 Next.js 和 eslint unresolved/imports 规则有同样的问题。

    【讨论】:

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