简体   繁体   English

为什么我收到错误无法解析模块路径? Eslint 与 Typescript

[英]Why I got error Unable to resolve path to module? Eslint with Typescript

I read many resources including Using eslint with Typescript-Unable to resolve path to module .我阅读了许多资源,包括Using eslint with Typescript-Unable to resolve path to module I got same error again and again.我一次又一次地遇到同样的错误。

yarn lint
  2:24  error    Unable to resolve path to module './components/Column'  import/no-unresolved
  2:24  error    Missing file extension for "./components/Column"        import/extensions
  3:22  error    Unable to resolve path to module './components/Card'    import/no-unresolved
  3:22  error    Missing file extension for "./components/Card"          import/extensions
  4:30  error    Missing file extension "ts" for "./components/styles"   import/extensions
  6:1   warning  Missing return type on function                         @typescript-eslint/explicit-module-boundary-types
  8:5   error    JSX not allowed in files with extension '.tsx'          react/jsx-filename-extension

eslinter.js eslinter.js

module.exports = {
  env: {
    browser: true,
    es2020: true,
  },
  extends: [
    'plugin:react/recommended',
    'plugin:import/typescript',
    'airbnb',
    'plugin:@typescript-eslint/recommended',
    'plugin:jest/recommended',
    'prettier',
    'prettier/react',
    'prettier/@typescript-eslint',
    'plugin:prettier/recommended'
  ],
  plugins: ['react', '@typescript-eslint', 'jest'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 12,
    sourceType: 'module',
    project: './tsconfig.json'
  },
  settings: {
    'import/resolver': {
        'node': {
            'paths': ['src'],
            'extensions': ['.js', '.ts', '.d.ts']
        },
    },
  },   
  rules: { 'linebreak-style': 'off',
      'no-use-before-define' : 'off',
      '@typescript-eslint/no-use-before-define': 'warn' }, 
};

I installed and have double checked all the dev dependecies.我安装并仔细检查了所有开发依赖项。 This is the part of the package.json这是package.json的一部分

  "devDependencies": {
    "@types/styled-components": "^5.1.7",
    "@typescript-eslint/eslint-plugin": "^4.15.1",
    "@typescript-eslint/parser": "^4.15.1",
    "eslint": "^7.20.0",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-airbnb-typescript": "^12.3.1",
    "eslint-config-prettier": "^7.2.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jest": "^24.1.5",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-prettier": "^3.3.1",
    "eslint-plugin-react": "^7.22.0",
    "eslint-plugin-react-hooks": "^4.2.0",
    "prettier": "^2.2.1"
  }

What should I try now?我现在应该尝试什么?

For me, it was fixed by adding "caseSensitive": false .eslintrc file eg:对我来说,它是通过添加"caseSensitive": false .eslintrc文件修复的,例如:

"settings": {
  "import/resolver": {
    "node": {
      "extensions": [".js", ".jsx", ".ts", ".tsx"]
    },
    "caseSensitive": false
  }
}

You can set the ESLint module import resolution by adding this snippet to your.eslintrc.json configuration file:您可以通过将此代码段添加到 your.eslintrc.json 配置文件来设置 ESLint 模块导入分辨率:

  

    settings: {
        'import/resolver': {
            'node': {
                'paths': ['src'],
                'extensions': ['.js', '.ts', '.d.ts', '.tsx']
            },
        },
      },   
      rules: { 'linebreak-style': 'off',
          'no-use-before-define' : 'off',
          '@typescript-eslint/no-use-before-define': 'warn',
          'react-native/split-platform-components': [
                2,
                {
                    "androidPathRegex": "\\.android.(js|jsx|ts|tsx)$",
                    "iosPathRegex": "\\.ios.(js|jsx|ts|tsx)$"
                }
          ]
      },

 

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

相关问题 eslint / typescript:无法解析模块路径 - eslint / typescript: Unable to resolve path to module 将 eslint 与打字稿一起使用 - 无法解析模块的路径 - Using eslint with typescript - Unable to resolve path to module Typescript/ESLint 错误:无法解析模块“aws-lambda”导入/未解析的路径 - Typescript/ESLint error: Unable to resolve path to module 'aws-lambda' import/no-unresolved 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) eslint:无法解析模块“src/interfaces”的路径 - eslint: Unable to resolve path to module 'src/interfaces' 无法解析模块“firebase-admin/app”的路径(ESLint) - Unable to resolve path to module 'firebase-admin/app' (ESLint) SAM Serverless Monorepo 的 ESLint “无法解析模块路径” - ESLint “Unable to resolve path to module” with SAM Serverless Monorepo React Native 与 TypeScript 错误无法解析模块 - React Native with TypeScript Error unable to resolve module React Native (Typescript) 绝对路径无法解析模块 - React Native (Typescript) Absolute path unable to resolve module React native Typescript 路径别名无法解析模块 - React native Typescript path alias unable to resolve module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM