【发布时间】:2020-11-06 18:46:02
【问题描述】:
尝试通过 https://create-react-app.dev/docs/adding-typescript 将 TypeScript 添加到已创建的 React 应用程序中
我在尝试启动时遇到以下错误:
> npx react-scripts start
Could not find a required file.
Name: index.js
Searched in: /home/karl/dev/afry/tmr-client/src
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tmr-client@0.1.0 start: `npx react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tmr-client@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/karl/.npm/_logs/2020-11-06T18_43_02_622Z-debug.log
我按照指南中的说明将 index.js 重命名为 index.ts。
【问题讨论】:
-
指南说要重命名为
index.tsx,而不是index.ts。 -
@JBallin AMAGHAWD。发表一个我会接受的答案。
-
由于对我的回答投了反对票,我正在重新讨论这个问题。我已经更新了我的答案,解释说我不清楚为什么这不起作用。您确定没有在父文件夹中安装
create-react-app或react-scripts吗?我想确保您使用的是最新版本。还注意到您直接使用 npx 调用react-scripts,而不是使用start脚本 - 但我认为这应该可行。
标签: reactjs typescript