reactjs - 找不到所需的文件。 - 将 TypeScript 添加到 React 项目

标签 reactjs typescript

尝试通过以下方式将 TypeScript 添加到已创建的 React 应用程序:https://create-react-app.dev/docs/adding-typescript
当我尝试启动时,我做了所有事情,但出现以下错误:

> 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。

最佳答案

我今天在使用 create-react-app 时遇到了同样的问题。问题是根据这个 Git 问题的 react-scripts 版本:Git Reference
一个快速的解决方案是更新 react-scripts。我正在使用 react-scripts 4.0.3 版,没有任何问题。
基于文档的安全方法:Create React App Docs将 package.json 文件中的 react-scripts 版本更改为最新的稳定版本,如“react-scripts”:“^4.0.3”。然后,运行 npm install从命令行。

关于reactjs - 找不到所需的文件。 - 将 TypeScript 添加到 React 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64720086/

相关文章:

javascript - React Uncaught TypeError : this. setState 不是函数

node.js - 定时器函数reactJS和NodeJS

node.js - 模块 'express' 未在 package.json 中列为依赖项

javascript - 如何使用 Typescript + react-leaflet 创建 GeoJSON Feature 元素

javascript - Angular - 从多个订阅中获取一个订阅

typescript - 如何在 VSCode 中查看大型 typescript 类型?

javascript - 如何让 Formik 返回一个 bool 值?

javascript - 错误 : ENOENT: no such file or directory, stat ... .steampath

javascript - React Bootstrap 自定义组件溢出栏

class - 为什么 Typescript 类会自动实现接口(interface)?