javascript - 在 create-react-app --template typescript 之后 TypeScript React 应用程序未呈现
问题描述
我使用npx create-react-app my-app --use-npm --template typescript
.
启动开发服务器 ( cd my-app
npm start
) 后,代码编译成功,但是当浏览器窗口打开时,什么都没有呈现。
控制台说:工人注册成功 http://localhost:3000/(但仍然没有渲染)
但有时也:未捕获的语法错误:预期的表达式,得到 '<'
我通常对 JavaScript 没有任何问题create-react-app
,但是对于 TypeScript,这会导致问题。我尝试使用不同版本的节点(14.0.0, 15.0.0, 15.0.1)(npm 版本7.0.2)和其他命令(npx create-react-app my-app --use-npm --typescript
(可能相同))但这没有帮助。
生成的.tsconfig文件:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
我的package.json文件中生成的依赖项:
"dependencies": {
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.6.3",
"@types/jest": "^26.0.20",
"@types/node": "^12.19.16",
"@types/react": "^17.0.1",
"@types/react-dom": "^17.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2",
"typescript": "^4.1.5",
"web-vitals": "^1.1.0"
},
解决方案
推荐阅读
- python - Python 3 写入 json 文件时出现双反斜杠问题
- python - 一种具有可变长度输入的热编码
- azure - 启用 Windows 安全事件的 Azure 安全中心 ARM 模板
- scala - 使用 Option[List[Long]] 时用 None 替换空列表
- linux - 找到所有具有特定扩展名的文件然后执行
- node.js - 在 Postgres 查询中调用本地函数
- python - 在填写用户名和密码时,元素在 selenium python 中不是难以处理的
- android - 提交失败,错误 0 文件已提交。不会添加文件别名 XXX 已存在于索引中
- matlab - 符号矩阵在 Matlab 中没有完全简化,但在 Octave 中简化了
- dji-sdk - DJIRTKState:distanceToHomePointDataSource 是 DJIRTKDataSource 类型而不是距离类型