【发布时间】:2021-01-11 00:51:53
【问题描述】:
我有一个用 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_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 作为依赖项(它肯定不在 package.json 中)。
【问题讨论】:
-
请将您的
tsconfig.json添加到问题中。 -
如果它在一个系统中运行而不是另一个系统。验证从 NodeJS 开始的所有工具的版本是否相同。
-
@AluanHaddad 我检查了一下,我的笔记本电脑有 Node v12,主计算机有 Node v14,但是当我将笔记本电脑更新到 v14 时仍然可以正常工作(而 main 失败了)。我应该检查哪些其他工具的兼容性?
-
检查纱线版本。将其克隆到笔记本电脑上的其他位置并验证它是否有效。可能是父目录中的某些类型正在被拾取。
-
将 Yarn 更新到 1.22.5 并在两台机器上再次克隆了所有内容,但仍然有一个给我错误。
标签: javascript node.js typescript create-react-app