使用React在VSCODE中自动导入不起作用

发布于 2025-01-28 02:07:17 字数 1478 浏览 2 评论 0原文

我有一个问题,不知道原因或如何解决。 VS代码不会强调导入的不正确路径,以防万一。同样,自动导入行不通。我尝试设置一个JSCONFIG文件以使用绝对路径,但没有任何结果。 我使用此 Extension> Extension> Extension for Auto Import。

JSCONFIG.JSON

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

ESLINTRC.JSON

{
  "env": {
    "node": true,
    "browser": true,
    "es2021": true
  },
  "extends": ["plugin:react/recommended", "prettier", "prettier/prettier", "plugin:prettier/recommended", "eslint:recommended"],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": ["react", "react-hooks"],
  "rules": {
    "no-return-await": "warn",
    "camelcase": "error",
    "react/jsx-key": "off",
    "react/prop-types": "off",
    "prettier/prettier": ["off", { "singleQuote": true }],
    "react/jsx-filename-extension": [
      "warn",
      {
        "extensions": [".jsx"]
      }
    ],
    "max-len": [
      "warn",
      {
        "code": 140
      }
    ],
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "off",
    "import/prefer-default-export": "off"
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}

是否有人知道我该怎么做才能突出显示错误的导入和自动导入工作?提前致谢!

I have an issue and don't know the reason or how to fix it. VS Code doesn't underline the incorrect path for imports in case if they are wrong. Also the auto import does not work. I tried to setup a jsconfig file to use the absolute paths, but without any result.
I use this extension for auto import.

jsconfig.json

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

eslintrc.json

{
  "env": {
    "node": true,
    "browser": true,
    "es2021": true
  },
  "extends": ["plugin:react/recommended", "prettier", "prettier/prettier", "plugin:prettier/recommended", "eslint:recommended"],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": ["react", "react-hooks"],
  "rules": {
    "no-return-await": "warn",
    "camelcase": "error",
    "react/jsx-key": "off",
    "react/prop-types": "off",
    "prettier/prettier": ["off", { "singleQuote": true }],
    "react/jsx-filename-extension": [
      "warn",
      {
        "extensions": [".jsx"]
      }
    ],
    "max-len": [
      "warn",
      {
        "code": 140
      }
    ],
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "off",
    "import/prefer-default-export": "off"
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  }
}

Does anybody know what I should do to get the wrong imports highlighted and the auto import working? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文