【TypeScript】使用CRA创建支持TS的React项目(从踩坑到放弃)

使用CRA创建支持TS的项目

本以为很简单的使用命令npx create-react-app react-ts-basic --template typescript,运行就可以了,硬生生的让我折腾了三个多小时。下面说说我的环境

  • win7
  • node 12.8.3
  • nvm-windows 1.1.9(为了电脑上能运行多个版本的node,进行各种版本测试)

eslint@8.21.0: The engine “node” is incompatible

win7 node 12.18.3下,报错:
eslint@8.21.0: The engine "node" is incompatible with this module. Expected version "^12.22.0 || ^14.17.0 || >=16.0.0". Got "12.18.3"
在这里插入图片描述
eslint需要12.18.3以上的node版本。

eslint-config-react-app@7.0.1: The engine “node” is incompatible with this module

win7 node 12.22.12下,报错:
eslint-config-react-app@7.0.1: The engine "node" is incompatible with this module. Expected version ">=14.0.0". Got "12.22.12"
在这里插入图片描述
eslint-config-react-app需要14.0.0以上的node版本。

无法定位程序输入点GetHostNameW于动态链接库WS2_32.dll上。

win7 node 14.20.0下,报错:
在这里插入图片描述

这是因为,新版本的node,不再支持win7(简单说就是,node使用了一些win7不存在的api,导致程序启动失败,报了上面的错误)。

换系统win10,使用node 14.20.0

之所以使用14.20.0是因为这是目前(2022-8-7)最新的14版本的node。

如果在win10下使用的是12的版本,会报下面错误

J:\_ALL\CODE\gitee>npx create-react-app react-ts-basic --template typescript
npx: installed 67 in 6.535s
You are running Node 12.16.1.
Create React App requires Node 14 or higher.
Please update your version of Node.

换系统macOs 11.5,使用node 14.18.13

完美避免了上面遇到的问题,直接运行成功!!!

参考资料

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜猫逐梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值