简体   繁体   English

eslint:无法解析模块“src/interfaces”的路径

[英]eslint: Unable to resolve path to module 'src/interfaces'

I'm having a very similar problem here and have tried every answer with no luck: Using eslint with typescript - Unable to resolve path to module我在这里遇到了一个非常相似的问题并且尝试了所有答案但没有运气: Using eslint with typescript - Unable to resolve path to module

Here is a screenshot of the linting error:这是 linting 错误的屏幕截图: 在此处输入图像描述

tsconfig.json tsconfig.json文件

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react",
    "lib": ["esnext", "DOM"],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": false,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "target": "esnext",
    "useUnknownInCatchVariables": true
  },
  "exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"],
  "include": ["src"]
}

eslintrc.json eslintrc.json文件

{
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"],
        "paths": ["src"]
      }
    },
    "react": "React",
    "version": "detect"
  },
  "env": {
    "browser": true,
    "es6": true,
    "jest": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "airbnb",
    "prettier",
    "plugin:import/typescript",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "allowImportExportEverywhere": true,
    "ecmaVersion": "latest",
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "plugins": ["react", "@typescript-eslint", "prettier", "jest"],
  "rules": {
    "array-element-newline": ["error", "never"],
    "camelcase": "off",
    "comma-dangle": ["error", "only-multiline"],
    "complexity": ["off"],
    "consistent-return": ["off"],
    "import/unresolved": ["off"],
    "import/extensions": ["off"],
    "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",
    "jsdoc/require-jsdoc": ["off"],
    "linebreak-style": ["off"],
    "max-len": ["error", {"code": 350, "tabWidth": 2}],
    "max-nested-callbacks": ["off"],
    "new-cap": ["off"],
    "no-console": ["warn"],
    "no-dupe-keys": ["error"],
    "no-nested-ternary": ["off"],
    "no-use-before-define": ["off"],
    "no-useless-catch": ["off"],
    "no-var": ["error"],
    "quotes": ["error", "single"],
    "react/display-name": ["off", {"ignoreTranspilerName": true}],
    "react/jsx-filename-extension": [1, {"extensions": [".js", ".jsx", ".tsx"]}],
    "semi": ["error", "always"],
    "@typescript-eslint/camelcase": "off",
    "@typescript-eslint/no-unused-vars": ["off"],
    "@typescript-eslint/explicit-module-boundary-types": ["off"],
    "@typescript-eslint/no-explicit-any": ["off"]
  }
}

prettierrc.json prettierrc.json

{
  "bracketSpacing": false,
  "jsxBracketSameLine": true,
  "singleQuote": true,
  "eslintIntegration": true,
  "trailingComma": "es5",
  "endOfLine": "auto",
  "printWdith": 120
}

I'm not sure why but removing the airbnb from the extends solved the issue.我不确定为什么,但是从extends中删除airbnb解决了这个问题。

change eslintrc.json from:将 eslintrc.json 更改为:

  "extends": [
    "eslint:recommended",
    "airbnb",
    "prettier",
    "plugin:import/typescript",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended"
  ],

to

  "extends": [
    "eslint:recommended",
    "prettier",
    "plugin:import/typescript",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended"
  ],

I hope one day there is a global linting file that will allow us to just use 1 so conflicts aren't creating these headaches.我希望有一天会有一个全局 linting 文件,它允许我们只使用 1,这样冲突就不会造成这些麻烦。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 eslint导入webpack:无法解析模块路径 - eslint imports in webpack: Unable to resolve path to module tsconfig 中的 eslint + typescript + 路径:ESLint:无法解析模块“@components/some-module”的路径。(import/no-unresolved) - eslint + typescript + path in tsconfig: ESLint: Unable to resolve path to module '@components/some-module'.(import/no-unresolved) Next.js + eslint:无法解析模块“fs/promises”的路径 - Next.js + eslint: unable to resolve path to module 'fs/promises' 无法解析模块“react-native-screens”(ESLint)的路径 - Unable to resolve path to module 'react-native-screens' (ESLint) 指向文件而不是目录时,Eslint 无法解析模块的路径 - Eslint's Unable to resolve path to module when pointing to file and not a directory Eslint + typescript 路径别名 - 无法解析模块的路径 - Eslint + typescript paths aliasing - Unable to resolve path to module [eslint]'react-redux'应该在项目的依赖项中列出,无法解析模块'react-redux'的路径 - [eslint]'react-redux' should be listed in the project's dependency+unable to resolve path to module 'react-redux' 无法解析模块“@nivo/pie”的路径 - Unable to resolve path to module '@nivo/pie' 无法解析模块“反应”的路径。 (导入/未解决) - Unable to resolve path to module 'react'. (import/no-unresolved) 无法在React本机应用程序中解析模块'./package.json'的路径 - Unable to resolve path to module './package.json' in React native application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM