Reputation: 40464
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.
Upvotes: 5
Views: 8006
Reputation: 9787
TLDR: npm i -D react-scripts@latest
I'm not sure why index.ts
isn't working for you, it seems to be supported.
The only explanation is that you're using an outdated version of react-scripts
, which you can update by simply running npm i -D react-scripts@latest
. More detail from Updating to New Releases:
Create React App is divided into two packages:
create-react-app is a global command-line utility that you use to create new projects. react-scripts is a development dependency in the generated projects (including this one). When you run npx create-react-app my-app it automatically installs the latest version of Create React App.
If you've previously installed create-react-app globally via npm install -g create-react-app, please visit Getting Started to learn about current installation steps.
Create React App creates the project with the latest version of react-scripts so you’ll get all the new features and improvements in newly created apps automatically.
To update an existing project to a new version of react-scripts, open the changelog, find the version you’re currently on (check package.json in this folder if you’re not sure), and apply the migration instructions for the newer versions.
In most cases bumping the react-scripts version in package.json and running npm install (or yarn install) in this folder should be enough, but it’s good to consult the changelog for potential breaking changes.
We commit to keeping the breaking changes minimal so you can upgrade react-scripts painlessly.
If this is the issue, you're relying on global installation of create-react-app
- which is not recommended given that it won't use the latest version. See note under Quick Start:
If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.
Upvotes: -1
Reputation: 674
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.
Upvotes: 9