facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.81k stars 26.87k forks source link

Changes to types in node_modules results in typescript errors while using the dev env #13466

Open vladiulianbogdan opened 11 months ago

vladiulianbogdan commented 11 months ago

Describe the bug

If I install a new version of a package with different typescripts types, the webpack process started by react-scripts start command does not take into consideration the newly added types and results in a typescript error.

Did you try recovering your dependencies?

not applicable

Which terms did you search for in User Guide?

Here https://facebook.github.io/create-react-app/docs/troubleshooting I have searched for "types".

Environment

Environment Info:

  current version of create-react-app: 5.0.1
  running from /Users/iulian-bogdanvlad/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

  System:
    OS: macOS 13.4
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 3.6.4 - ~/.nvm/versions/node/v16.17.0/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
  Browsers:
    Chrome: 119.0.6045.199
    Edge: Not Found
    Firefox: 115.0.3
    Safari: 16.5
  npmPackages:
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    react-scripts: 5.0.1 => 5.0.1
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. Run create react app with typescript template.
  2. Create a package P that contains some types and publish it to npm
  3. Import the types from P in your app and use them somewhere
  4. run npm start
  5. Update the P package, by adding a new type.
  6. Run npm install P to install the latest version while npm start is still running.
  7. Import the new type and use it in your code.
  8. npm start will complain that the new type does not exist and there is no way to make it work without restarting. The webpack bundling finishes correctly, but the type checking fails.

Expected behavior

I would expect that the newly added type to be seen by npm start without restarting it.

Actual behavior

I receive an error and I have to restart npm start to make it work again.

Screenshot 2023-12-04 at 12 29 55

Reproducible demo

Here I have a simple CRA app. The project uses a library test-getting-started-genezio-typescript-newest_us-east-1 that has two versions: 1.0.0-local and 1.0.1-local the only difference between the two is that the 1.0.1 has a new type. First install 1.0.0, run npm start, then install 1.0.1, use the new type.