在src目录中创建React App(TypeScript)自动生成react-app-env.d.ts

mat*_*rin 8 typescript create-react-app

内容:

我只是将一个应用从移植create-react-app-typescriptcreate-react-app。在结构相同但不同的应用程序中,我执行了相同的步骤。

脚步:

npm uninstall react-scripts-ts
npm install react-scripts
npm install --save typescript @types/node @types/react @types/react-dom @types/jest
Run Code Online (Sandbox Code Playgroud)

详细步骤

第二个应用程序特有的问题:

  • 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?

mat*_*rin 5

有用的信息:

与预期的一样,有一个导致问题的空文件,但它不是生成的src/react-app-env.d.ts文件。

个人背景:

自动监视脚本将一个空文件复制到问题项目中。自动脚本永远不会清除目标位置,因此空文件会四处徘徊,后来又引起了此问题。

实际答案:

确保没有空(.ts)文件。

虽然这是解决了我的问题的实际答案,但我仍然不知道为什么一个项目生成src/react-app-env.d.ts文件而另一个项目却不生成文件。


Yuv*_*til 5

这是一个已知的错误。React 团队尚未修复它。现在你可以通过在里面添加以下内容来忽略这个文件.gitignore

/src/react-app-env.d.ts
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,查看https://github.com/facebook/create-react-app/issues/6560

  • 您不应该将其添加到 .gitignore。https://github.com/facebook/create-react-app/issues/6560#issuecomment-792323361 (3认同)