typescript - 除非在我执行 yarn start 时提供了“--jsx”标志,否则无法使用 JSX
问题描述
我做了
- 我做了 yarn start 并且
http://localhost:3000/
成功了,但是出现了很多问题
$yarn start
也 npm run start
yarn run v1.22.4 $ react-scripts start
The following changes are being made to your tsconfig.json file:
- compilerOptions.jsx must be react-jsx (to support the new JSX transform in React 17)
i 「wds」: Project is running at http://192.168.56.1/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\taiga\Github\Typescript\eslint-app\example\public
i 「wds」: 404s will fallback to /
Starting the development server...
Compiled successfully!
You can now view example in the browser.
Local: http://localhost:3000
On Your Network: http://192.168.56.1:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
错误
Cannot use JSX unless the '--jsx' flag is provided
Module './App' was resolved to 'c:/Users/taiga/Github/Typescript/eslint-app/example/src/App.tsx', but '--jsx' is not set.
Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'.
我试试
这是我的回购
我的目标
- 使用皮棉
react-typescript-app
解决方案
- 在使用 CRA(创建反应应用程序)初始化项目后,它是否可以正确编译/工作?
可能是你更新的包,用 CRA 初始化后尝试编译它而不更新任何包。(https://github.com/taiga-programming/example-typescript/commit/b7074af02df6ce469b867a69625d5c1de7a209eb)
但首先,您的提交https://github.com/taiga-programming/example-typescript/commit/88ee7bfb164d9017883ea91535fadeb7e17691aa中的 tsconfig.json 有一些可疑之处:
- "jsx": "react-jsx"
+ "jsx": "react"
试着放"jsx": "react-jsx"
回去。
推荐阅读
- r - 如何使用错误消息修复软件包 marmap 的安装?
- javascript - 如何在 react js 中实现 DIAL 协议?
- php - 将所有域重定向到单个 https 域
- python - 如何使用 django 在 postgresql 中保存 UTC 时间而不偏移
- java - 在 springdoc-openapi-ui 中为承载令牌身份验证(JWT)启用授权按钮
- c# - 范围服务 - 每个请求是否相同?感觉我的代码中使用了多个副本
- azure - Azure 时序见解预览版编写的 Parquet 文件不可读
- go - 使用 Go 从带有 Oauth2 身份验证的 Restful API 消费
- sql - SQL 多次减少一个值
- database - 从 PostgreSQL 版本 11 恢复数据库时出现问题