Skip to content

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

Closed
@jdpigeon

Description

@jdpigeon

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions