简体   繁体   English

“找不到‘async’的类型定义文件。TS2688”

[英]"Cannot find type definition file for 'async'. TS2688"

I have a react/typescript app made with create-react-app我有一个用create-react-app制作的 react/typescript 应用create-react-app

When I try to yarn start in my computer i get the following error:当我尝试在计算机中yarn start ,出现以下错误:

Failed to compile.

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

I don't understand why is this error happening.我不明白为什么会发生这个错误。 Why would async need a type definition?为什么async需要类型定义? And why is it not finding it?为什么它没有找到它?

I already tried removing node_modules and yarn.lock and doing `yarn install``我已经尝试删除node_modulesyarn.lock并执行 `yarn install`

I also tried removing the whole folder and cloning my repo again (and installing everything again).我还尝试删除整个文件夹并再次克隆我的存储库(并再次安装所有内容)。

Curiously, this works perfectly fine in my laptop when I clone the repo:奇怪的是,当我克隆 repo 时,这在我的笔记本电脑上运行得非常好:

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

package.json : 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"]
}

I edited the file that was giving me the async problem (I removed async) and I keep getting the same error.我编辑了给我带来异步问题的文件(我删除了异步),但我不断收到相同的错误。

Atom Linter gives me an error at the start of tsconfig.json like this: 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' .

Im stumped because I didn't add graphql as a dependency (it is certainly not in package.json ).graphql过,因为我没有添加graphql作为依赖项(它肯定不在package.json )。

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

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

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