首页 > 解决方案 > “找不到‘异步’的类型定义文件。TS2688”

问题描述

我有一个反应/打字稿应用程序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_modulesyarn.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为依赖项(它肯定不在package.json)。

标签: javascriptnode.jstypescriptcreate-react-app

解决方案


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


推荐阅读