gpt4 book ai didi

javascript - 在 JSConfig.json 文件中看到未知的 typescript 错误

转载 作者:行者123 更新时间:2023-12-05 08:15:57 28 4
gpt4 key购买 nike

我在我的项目中添加了一个 jsconfig.json,但出于某种原因,我收到了一个 typescript 错误,指出未找到 dotenv/types。我终生无法弄清楚为什么会出现此错误。我什至尝试将 dotenv 添加到我的 package.json 中,但它并没有解决我的问题。

这是一个使用 create-react-app 创建的标准项目,我添加了 jsconfig.json 以允许绝对导入

// jsconfig.json    
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}

异常(exception):

File '/Users/path/to/file/node_modules/dotenv/types' not found.

其他可能有用的潜在文件:

package.json

{
"name": "quantous-spa",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.20.0",
"babel-plugin-macros": "^2.8.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-feather": "^2.0.8",
"react-loading-skeleton": "^2.1.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"styled-components": "^5.1.1",
"typeface-muli": "^1.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.6",
"prettier": "^2.0.5"
},
"resolutions": {
"styled-components": "^5"
}
}

.eslintrc

{
"env": {
"browser": true,
"es2020": true
},
"extends": [
"plugin:react/recommended",
"google",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"js": true
},
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["react"],
"rules": {
"require-jsdoc": "off"
},
"settings": {
"import/resolver": {
"node": {
"paths": ["node_modules", "src/"]
}
}
}
}

screeshot of vscode error

最佳答案

如果您使用的是 Visual Studio Code,只需在设置中禁用“Typescript 验证”即可。

错误应该消失了。

enter image description here

关于javascript - 在 JSConfig.json 文件中看到未知的 typescript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63525778/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com