create-react-app: Hot reloading breaks when encountering Typescript error
Describe the bug
I am having exactly same issue as metioned in https://github.com/facebook/create-react-app/issues/8055
Since that issue is now closed, I will just re-describe the issue again here.
Hot reloading seems to stop working when a Typescript compilation error is encountered. Any subsequent code changes would not trigger hot reloading after that, even if I fix the lines that would cause compile errror.
I need to actually close and restart the dev server in order to see my changes reflected.
Which terms did you search for in User Guide?
Typescript, Hot reloading
Environment
System:
OS: Linux 4.19 Ubuntu 18.04.2 LTS (Bionic Beaver)
CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
Binaries:
Node: 13.7.0 - /usr/bin/node
Yarn: 1.21.1 - /mnt/c/Program Files (x86)/Yarn/bin/yarn
npm: 6.14.2 - /usr/bin/npm
Browsers:
Chrome: Not Found
Firefox: Not Found
npmPackages:
react: ^16.13.0 => 16.13.0
react-dom: ^16.13.0 => 16.13.0
react-scripts: 3.4.0 => 3.4.0
npmGlobalPackages:
create-react-app: 3.4.0
Steps to reproduce
create-react-app react-app --template typescript
cd react-app
yarn start
- Write invalid typescript code in
src/App.tsx
and save it to trigger compilation error - See TS compiler error message in terminal
- Fix the code in
src/App.tsx
and save it - Note that hot reloading is now NOT triggered
- Killing dev server and running
yarn start
again to see changes get reflected
Expected behavior
Re-compile and hot reload on every save, just like when using create-react-app
without the --template typescript
flag
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 78
- Comments: 50
Guys, there seems to be a silly (but ugly) workaround. Anyway better than restarting the dev server I think. Please try the following:
I have a similar problem, maybe not be the exact same problem, but I wonder if it’s related. My problem is that if I have a TypeScript error in a file which isn’t actually imported (yet or any more) by any other module descending from the entry point, saving it doesn’t trigger recompiling. For the recompiling to start, I have to go to a file that is actually imported somewhere in the import tree starting from index.tsx and just save it (without changes). A bit annoying, while not the biggest of problems.
still happening
Having this same issue and the above commend unfortunately didn’t fix it
I have created a repo that is a fresh CRA install (
4.0.3
), that demos the bug: https://github.com/k-funk/cra-issue-8667https://user-images.githubusercontent.com/1933021/124847551-57516400-df58-11eb-8335-4952ce3d0c2e.mp4
still happening
Solution posted by @sanojck works for me a lot of the time, but not always. It would be really nice if this issue was fixed entirely.
Same problem in macOS 10.15
Hi all, found a quick and effective fix that will hopefully work for all of you. Like others, I had found that re-saving the index.tsx would trigger the reload. I revisited the tsconfig.json and changed the ‘include’ parameter from:
to:
This ensured that the index file was being tracked as the root and then triggered the reload. Strange that this is necessary but it worked!
I am having the same issue as others, I tried all “solutions” and none of them work. If I make one small TS mistake, I have to restart npm just to see any new changes I make, every single time.
React: 17.0.1 and 17.0.2 TypeScript: 4.1.2 and 4.2.4
Update, I did further testing and discovered this which “fixed” it for me:
If I import a file but don’t actually implement it in my component, TS will report errors as usual if there are any, but any changes I make — whether or not I fix the error — will not hot reload.
However, when I do implement the imported file, such as putting it in my component as a var in a console.log, it will hot reload just fine.
This was confusing because I had imported a file that already had an error in it, but I never actually implemented it in my component because of the error, and at this point, hot reloading wouldn’t work.
It’s driving me crazy, at 04:44AM
Same with both
.ts
or.tsx
files.Me too having almost the same issue. In my case, changes saved on “normal” .tsx files, which would fix previous typescript errors, would fire HotReload; but the same scenario is not working in the case of *.stories.tsx files.
Hope the team fix these issues soon. Thanks 😃
Facing this same issue:
I think the problem is that the TS loader did not generate a new .js file in this case due to syntax error, etc. therefore the webpack devserver did not pick up any file changes.
not sure what the best approach is to solving this. and possibly barking at the wrong tree here since it’s more of a TS and webpack issue.
Same issue, nothing worked for me except re-starting the development server.
Encountering the same error on .ts files, Hot reloading seems to work on .tsx however
linux mint, adding --reset-cache worked for me: