reactjs - eslint:无法解析模块 'src/interfaces' 的路径

标签 reactjs typescript eslint prettier

我在这里遇到了一个非常相似的问题,并且尝试了每个答案但没有运气:Using eslint with typescript - Unable to resolve path to module

这是 linting 错误的屏幕截图: enter image description here

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

{
  "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

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

最佳答案

我不知道为什么,但从 extends 中删除 airbnb 解决了这个问题。

将 eslintrc.json 更改为:

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

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

我希望有一天有一个全局 linting 文件,允许我们只使用 1,这样冲突就不会造成这些麻烦。

关于reactjs - eslint:无法解析模块 'src/interfaces' 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72017864/

相关文章:

reactjs - 带有持久抽屉的 React 路由

reactjs - 如何从 React 中的 eslint 解析器中排除 css 文件

javascript - 如何修复此 ""ESLing 错误?

javascript - 调色板中的 MUI 自定义命名选项 - 类型 'primary' 上不存在属性 'TypeBackground'

javascript - React 中的类分配

javascript - 不要使用 Router React js 渲染搜索组件

reactjs - SwiperJS 导航不显示

javascript - TextInput 中的值没有改变?

javascript - 从库导出枚举并在消费者 typescript 项目中使用它

typescript - var 声明隐藏模块内的接口(interface)