使用create-react-app创建TS项目后npm start报错:Cannot read properties of undefined (reading 'stdin')
解决方案:npm ERR! Cannot read properties of undefined (reading 'stdin')
1. 检查终端交互性
这个错误大多和终端无法正常访问stdin有关,比如在非交互式环境(部分IDE内置终端、后台脚本)运行命令,或是终端权限异常。
- 切换到系统原生终端(Windows用CMD/PowerShell,macOS/Linux用Terminal),重新执行
npm start - 如果用IDE终端,确认开启了交互式模式,比如VS Code可通过终端面板右上角下拉菜单选择「新建终端」,确保是交互式会话
2. 清理缓存并重装依赖
缓存损坏也可能引发这类异常:
- 执行命令清除npm缓存:
npm cache clean --force - 删除项目根目录下的
node_modules文件夹和package-lock.json文件 - 重新安装依赖:
npm install - 再次尝试启动项目:
npm start
3. 降级npm版本
npm 9.x与Node 18.x部分组合存在兼容性问题,可降级到稳定版本:
- 全局降级npm:
npm install -g npm@8.19.4(该版本和Node18适配性较好) - 返回项目目录,重新安装依赖后启动
4. 更新create-react-app后重建项目
可能是模板版本问题,尝试用最新版create-react-app重新创建项目:
- 卸载全局create-react-app:
npm uninstall -g create-react-app - 执行最新创建命令:
npx create-react-app@latest my-app --template typescript - 进入新创建的项目,执行
npm start
内容的提问来源于stack exchange,提问作者Sudharsan
相关产品推荐
相关产品推荐

