下一个导入/无未解析的eslint nextjs模块路径

bsxbgnwa  于 2023-05-06  发布在  其他
关注(0)|答案(1)|浏览(134)

我使用的是从next导入模块。尝试导入这样的组件。
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。似乎不起作用。

xlpyo6sf

xlpyo6sf1#

在您的eslintrc.json中,您有

["@components", "./components/*"],

你应该有:

["@/components", "./components/*"]

换句话说,在@components之间应该有一个/,因为jsconfig.json中的路径别名是

"@/components/*": // ...,

相关问题