"Cannot find type definition file for 'async'. TS2688"



我有一个用create-react-app制作的react/typescript应用程序

当我尝试在我的计算机中yarn start时,我得到以下错误:

Failed to compile.
undefined
TypeScript error in undefined(undefined,undefined):
Cannot find type definition file for 'async'.  TS2688

我不明白为什么会发生这种错误。为什么async需要类型定义?为什么它找不到它?

我已经尝试删除node_modulesyarn.lock并执行"纱线安装"`

我还尝试删除整个文件夹并再次克隆我的repo(并再次安装所有内容(。

奇怪的是,当我克隆repo:时,这在我的笔记本电脑中运行得非常好

https://github.com/grochadc/filex-workshops-registration

package.json:

{
"name": "typescript-react-testing",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "10.0.0",
"@testing-library/user-event": "^12.1.5",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/yup": "^0.29.7",
"bootstrap": "^4.5.2",
"dotenv": "^8.2.0",
"firebase": "^7.21.0",
"formik": "^2.1.5",
"json-server": "^0.16.1",
"mutation-observer": "^1.0.3",
"react": "^16.13.1",
"react-bootstrap": "^1.3.0",
"react-dom": "^16.13.1",
"react-responsive": "^8.1.0",
"react-scripts": "3.4.3",
"styled-components": "^5.2.0",
"typescript": "4.0.3",
"yup": "^0.29.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"json-server": "json-server --watch db.json --port 5000"
},
"proxy": "http://localhost:5000",
"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": {
"@testing-library/dom": "^7.24.2",
"jest-fetch-mock": "^3.0.3"
}
}

tsconfig.json

{
"compilerOptions": {
"noImplicitAny": false,
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
}

我编辑了导致异步问题的文件(我删除了异步(,但我一直收到同样的错误。

Atom Linter在tsconfig.json开始时给我一个错误,如下所示:

Cannot find type definition file for 'async' .
Cannot find type definition file for 'graphql' .
Cannot find type definition file for 'isomorphic-fetch' .

我被难住了,因为我没有添加graphql作为依赖项(它肯定不在package.json中(。

这可能与您使用的节点版本有关。最低版本应该是nvm 10.18,所以请确保您有正确的依赖关系。