Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find a required file. - Adding TypeScript to React project

Trying to add TypeScript to an already created React app via: https://create-react-app.dev/docs/adding-typescript

I do everything bu get the following error when I try and start:

> 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! [email protected] start: `npx react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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

I renamed the index.js to index.ts as stated in the guide.

like image 362
basickarl Avatar asked Nov 06 '20 18:11

basickarl


People also ask

What is create react app?

Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in React. It sets up your development environment so that you can use the latest JavaScript features, provides a nice developer experience, and optimizes your app for production.


1 Answers

I faced the same issue today with create-react-app. The problem is the version of react-scripts as per this Git issue: Git Reference

A quick solution is to update react-scripts. I am using react-scripts version 4.0.3 with no issues.

A safe way to do it based on the documentation: Create React App Docs would be to change the version of react-scripts in the package.json file to the most recent stable version like "react-scripts": "^4.0.3". Then, run npm install from the command line.

like image 115
Towerss Avatar answered Oct 23 '22 18:10

Towerss