Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create React App (TypeScript) auto-generating react-app-env.d.ts in src directory

Context:

I just ported one app from create-react-app-typescript to create-react-app. In a identically structured but different app, I did the same steps.

Steps:

npm uninstall react-scripts-ts
npm install react-scripts
npm install --save typescript @types/node @types/react @types/react-dom @types/jest

Detailed Steps

Problems unique to second app:

  • Type error: Cannot compile namespaces when the '--isolatedModules' flag is provided. TS1208
  • Generated file src/react-app-env.d.ts

Assumption:

The generated file src/react-app-env.d.ts causes the --isolatedModules error.

Actual Question:

How do I prevent react-scripts from generating the src/react-app-env.d.ts file upon react-scripts start?

like image 629
mattferrin Avatar asked Nov 28 '18 20:11

mattferrin


People also ask

What is react app ENV D TS file?

Next, there is a new react-app-env. d. ts file in the src folder. This file references TypeScript types declarations that are specific to projects started with Create React App. These type declarations add support for importing resource files such as bmp, gif, jpeg, jpg, png, webp, and svg.

Does create react app use TypeScript?

Create react app is basically a node package that we can simply install. The interesting part about this is that you can use it with TypeScript very easily by leveraging the use of npm or yarn depending on what your package manager preference is.


1 Answers

Useful info:

As expected there was an empty file causing an issue, but it was not the generated src/react-app-env.d.ts file.

Personal context:

An automated watch script copied an empty file into the problem project. The automated scripts never clean the destination, so the empty file hung around and later caused this issue.

Actual answer:

Make sure there are no empty (.ts) files.

While this is the actual answer in the sense that it solved my problem, I still don't know why one project generates a src/react-app-env.d.ts file while the other does not.

like image 85
mattferrin Avatar answered Oct 04 '22 21:10

mattferrin