Skip to content

Cannot find type definition file for 'react-scripts' in custom react-scripts #5875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jdpigeon opened this issue Nov 22, 2018 · 1 comment
Closed

Comments

@jdpigeon
Copy link

Noticed what might be a small footgun for people forking react-scripts to create their own.

I was almost done setting up my custom react-scripts fork when I got this error:

/home/dano/src/ctrlpanel-ts/src/react-app-env.d.ts
Type error: Cannot find type definition file for 'react-scripts'.  TS2688

  > 1 | /// <reference types="react-scripts" />
      |                       ^
    2 |

The problem was fixed in my project by changing the types string in react-app-env.d.ts to match the name of my react-sripts package. (e.g. "react-scripts" -> "@company/react-scripts")

After some sleuthing, I found out that, although custom script names are handled in config/paths.js by using ownPackageJson.name, it's hardcoded in verifyTypeScriptSetup.js

 // Reference `react-scripts` types
  if (!fs.existsSync(paths.appTypeDeclarations)) {
    fs.writeFileSync(
      paths.appTypeDeclarations,
      `/// <reference types="react-scripts" />${os.EOL}`
    );
  }

Perhaps this should be modified to check the package.json for a name?

@Timer
Copy link
Contributor

Timer commented Nov 22, 2018

PR at #5827

Thanks!

@Timer Timer closed this as completed Nov 22, 2018
@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants