[英]"Cannot find type definition file for 'async'. TS2688"
我有一個用create-react-app
制作的 react/typescript 應用create-react-app
當我嘗試在計算機中yarn start
,出現以下錯誤:
Failed to compile.
undefined
TypeScript error in undefined(undefined,undefined):
Cannot find type definition file for 'async'. TS2688
我不明白為什么會發生這個錯誤。 為什么async
需要類型定義? 為什么它沒有找到它?
我已經嘗試刪除node_modules
和yarn.lock
並執行 `yarn install`
我還嘗試刪除整個文件夾並再次克隆我的存儲庫(並再次安裝所有內容)。
奇怪的是,當我克隆 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
過,因為我沒有添加graphql
作為依賴項(它肯定不在package.json
)。
這可能與您使用的節點版本有關,最低版本應為 nvm 10.18,因此請確保您具有正確的依賴項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.