react-native: Fast refresh not working in React Native 0.64.2
Description
Fast refresh is not working in React Native 0.64.2. I have created the most barebones out of the box setup I could.
When I have the app running and I save a file, I expect to see the changes refreshed and visible in the app.
What is actually happening is that I need to stop and restart Metro to see the changes I have made.
I followed the environment setup instructions - opting to create a brand new project following the React Native CLI Quickstart path.
I also ensured that I do not have the react-native cli tool installed globally. This project is using the latest stable version of React Native (0.64.2).
React Native version:
Running npx react-native info yields the following:
System:
OS: macOS 11.5.1
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 1.92 GB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 15.4.0 - ~/.nvm/versions/node/v15.4.0/bin/node
Yarn: 1.22.4 - ~/.yarn/bin/yarn
npm: 7.0.15 - ~/.nvm/versions/node/v15.4.0/bin/npm
Watchman: 2021.06.07.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK:
API Levels: 29, 30
Build Tools: 29.0.3, 30.0.0, 30.0.1, 30.0.2, 30.0.3, 31.0.0
System Images: android-28 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.7199119
Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_265 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.1 => 17.0.1
react-native: 0.64.2 => 0.64.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
You will need:
- Node v15.4.0
- nvm to easily switch between node versions
- CocoaPods v1.10.1
- Xcode 12.5.1
- Clone this repository
- Run the command
nvm useto switch to the version of node that we need. - Install yarn dependencies with
yarn - Install cocoapods dependencies with
pod install --project-directory=ios - Start the Metro bundler with
yarn start - Start Xcode, then open the project by loading ios/FastRefresh.xcworkspace
- Press the play button in Xcode to build and run the project.
Expected Results
When I edit some text in App.js, I would expect to see the changes appear in the running instance of the app.
Link to example repository
I have created a simple example app to demonstrate the issue => https://github.com/matfin/rn-fastrefresh-bug
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 42 (8 by maintainers)
This is still broken in 0.65.1… I have to reload the metro to see any changes. It says “refreshing” but no actual changes are reflected.
I am having similar problems.
I’m on the latest RN 0.66.2 => the Metro Bundler is not able to dynamically perform Fast Refresh bundle to the iOS simulator and Android emulator when started in MacOS default terminal in a normal way.
NOT WORKING
npx react-native run-iosornpx react-native android, the Metro bundler automatically starts in the MacOS default terminal => the Fast Refresh doesn’t work.npx react-native startin the MacOS default terminal and then run the run-ios/run-android commands => The Fast Refresh doesn’t work.WORKING
sudo npx react-native start --reset-cachein a new MacOS default terminal => The Fast Refresh work correctly.npx react-native startin a new iTerm2 window => The Fast Refresh work correctly.In any case, the easiest workaround for me is just to keep an iTerm2 window running Metro Bundler all the time for the root project I am on.
You can access your debug menu to check whether it is enabled or disabled. If you have your “Fast Refresh”, then it sometimes glitches according to your workspace setup and memory consumption. Therefore, continue reading the next section.
Read Carefully! Do not just run the command!
There’s a workaround I sometimes use if the workspace is managed by
gitbut take extra good care while using this as you might mess up yourgittree. Here’s a short description about “What is a Git index.lock file?” Run the following command from your project root as it sometimes helps to refresh your workspace (not always) and then resave any of your files.@mikehardy Why, I’m not the RN expert here. You seem to be, you should know right?
I mean, you don’t ask a medical intern to diagnose an issue and try to solve it by themselves by trial and error, when the resident physician is there to help. If the resident don’t know, they get help from the attending physican.
I hope you get my point. People where don’t know, doing it by trial and error, suggesting solutions that might not really work. While the resident RN experts seem to not know too, and should raise this issue to the people further up who SHOULD know.
But If this is how things work here (ie let the community figure it out by trial and error, hoping something will fix it) then fine i guess 😂😂
A few days later I found out what caused it. I am using mobx 6 on a project and the documentation states what needs to be added to
babel.config.jsis(@babel/plugin-proposal-class-properties):As soon as I remove the connection of this plugin, everything starts working normally. At the moment I don’t understand how this affects metro and how I can still use the specified plugin. I tried to make various configurations.
it is also worth paying attention to this comment
this works, but why, what’s the interaction between watchman, swap files and fast refresh? these things seem completely unrelated to me
:set noswapfilein Vim also seems to fix it for me. Thanks for that tip!I was seeing fast refresh not working when going from react-native 0.63.3 to 0.64.0. Turned out the issue was 0.63.3 used to have fast refresh always enabled by default because of a bug (https://github.com/facebook/react-native/issues/29912#issuecomment-822825875) which was fixed in 0.64. Now you need to go in the debug menu and turn it on using “Enable Fast Refresh”.
I faced this issue yesterday. Took some time to find out that it was because of the swap file that gets created on edit.
Disabling the swap file solved the problem for me. Unsure if it’s relevant.
I can’t believe such a stupid-simple solution was my problem, thanks @jgolden 😅
I am experiencing a similar problem. All methods have already been tried. Cleaned gradle, metro-cache, watchman, npm-cache. Reinstalled npm dependencies. I think I got this bug after I wanted to make hermes debugger for flipper work by running the
npm run start --host localhostcommand. In my case, console.log output does not occur, http requests do not work, fast-refresh does not work. Everything was fine until today. All of the above methods have been tried and not only they - unsuccessfully.I have no involvement in this issue @projectnetworld why did you tag me? Either way, I just happened to have the react-native-permissions example up while testing something else and it happens to be based on react-native 0.64.2 at the moment. I just altered some text on the example app screen and it fast-refreshed.
So I can’t reproduce on react-native 0.64.2
Not sure if the “requires node v15.xx” is strict for this issue, as I’m using node 14.17.6, perhaps that is a difference
Just to add to this, if I run with sudo:
Then fast refresh works. If I do not, then fast refresh doesn’t work.