I ran the command npx create-react-app my-app --template typescript
and when I tried to start the project with npm start
, I got the following errors.
Starting the development server...
One of your dependencies, babel-preset-react-app, is importing the
Failed to compile.
Module not found: Error: Can't resolve './App' in 'PATHreddit-reactsrc'
ERROR in ./src/index.tsx 7:0-24
Module not found: Error: Can't resolve './App' in 'PATHreddit-reactsrc'
ERROR in ./src/index.tsx 8:0-48
Module not found: Error: Can't resolve './reportWebVitals' in 'PATHreddit-reactsrc'
ERROR in [eslint] Failed to load parser '@typescript-eslint/parser' declared in 'package.json » eslint-config-react-app#overrides[0]': Cannot find module 'typescript'
Require stack:
- PATHreddit-reactnode_modules@typescript-eslinttypescript-estreedistconvert.js
- PATHreddit-reactnode_modules@typescript-eslinttypescript-estreedistast-converter.js
- PATHreddit-reactnode_modules@typescript-eslinttypescript-estreedistparser.js
- PATHreddit-reactnode_modules@typescript-eslinttypescript-estreedistindex.js
- PATHreddit-reactnode_modules@typescript-eslintparserdistparser.js
- [email protected]
- [email protected]
webpack compiled with 3 errors
Why is this happening and how can I fix it?
2
Answers
When I was creating the React App the file react-app-env.d.ts was missing and I had a lot of issues. After installing and trying different versions of Node with nvm I managed to get it working with the latest lts version.
I ran into the same issue yesterday I just updated the node version to v20 ( I was using node v14 you can run
node -v
to see what version you are using ) then ran npm install after deletingpackage.lock
andnode_modules
and all things worked with me.