简体   繁体   English

即使在添加 jsconfig 后,Visual Studio Code React 也没有显示错误

[英]Visual Studio Code React not showing error even after adding jsconfig

So I am building a REACT JS project, and after a while I noticed that it doesn't underline undefined functions nor wrong imports, for example if I does that:所以我正在构建一个 REACT JS 项目,过了一会儿我注意到它没有强调未定义的函数或错误的导入,例如如果我这样做:

import React, { useState } from 'reactaeasdfas';

it wont say that reactaeasdfas is undefined.它不会说reactaeasdfas是未定义的。

After a bit of searching I found that people say that jsconfig.json should be initialized.经过一番搜索,我发现人们说应该初始化jsconfig.json

I found a basic one on the inte.net:我在 inte.net 上找到了一个基本的:

{
    "compilerOptions": {
      "module": "commonjs",
      "target": "es6",
      "jsx": "react"
    },
    "include": [
        "src"
    ]
}

This code above does solve the problem that if I call an undefined function, it will underline it in red, but it still doesn't work if I include undefined import.上面这段代码确实解决了如果我调用一个未定义的function,它会用红色下划线的问题,但是如果我包含未定义的导入它仍然不起作用。

Note: I installed react project via create-react-app注意:我通过create-react-app安装了 react 项目

Install the ESLint extension for Visual Studio Code - https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint安装 Visual Studio Code 的 ESLint 扩展 - https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint

More details:更多细节:

A standard create-react-app package is already using ESLint, so you shouldn't need to make any changes to the app.标准的 create-react-app package 已经在使用 ESLint,因此您不需要对应用程序进行任何更改。 However, your editor needs to be set up to work with ESLint.但是,您的编辑器需要设置为使用 ESLint。 For VS Code this is done by installing an extension/plugin.对于 VS Code,这是通过安装扩展/插件来完成的。 The CRA documentation has more information about setting up editors - https://create-react-app.dev/docs/setting-up-your-editor/ CRA 文档包含有关设置编辑器的更多信息 - https://create-react-app.dev/docs/setting-up-your-editor/

Maybe this article can help?也许这篇文章可以提供帮助? I just tried it and it worked for me https://blog.echobind.com/integrating-prettier-eslint-airbnb-style-guide-in-vscode-47f07b5d7d6a我刚刚尝试过,它对我有用 https://blog.echobind.com/integrating-prettier-eslint-airbnb-style-guide-in-vscode-47f07b5d7d6a

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM