How to clean react native project?
Is there any way to clean react native project as we can clean xcode project?
Any help will be appreciated!
A react-native Project is about one XCode Project and one Android Project. (for pure js code, there's no need to do clean)
So, what you need would be
Clean XCode Project with
cd ios
xcodebuild clean
And then clean Android Project with
cd android
./gradlew clean
You can simply write a batch file for it.
For android project
cd android &&./gradlew clean && cd ../
For iOS project
cd ios && xcodebuild clean && cd ../
If you need build clean again and again then add this scripts in the package.json file like this
scripts: {
"clean:android": "cd android && ./gradlew clean && cd ../",
"clean:ios": "cd ios && xcodebuild clean && cd ../",
}
Then run for android
yarn clean:android
And run for iOS
yarn clean:ios
For Android
cd android
gradlew clean
For IOS
cd ios
xcodebuild clean
Delete node modules and
npm ci
react-native link
followed by
react-native start --reset-cache
React Native clean-project is now the best and easiest way to do deal with react-native artifacts and cleanup. Since it's automatically detected by react-native, it becomes its own command in react-native.
$ yarn add -D react-native-clean-project
$ react-native clean-project
this script will clean the Android and IOS build cache, then removes node modules and caches, and reinstall the react native project.
# rm -rf $HOME/.gradle/caches/
cd android && ./gradlew cleanBuildCache
cd ..
cd ios && pod cache clean --all && rm -rf build
cd ..
rm -rf node_modules
yarn cache clean --force
yarn install
cd ios && pod install
To reset the iOS simulator and erase all simulator data, focus on the simulator then go to Hardware -> Erase All Content and Settings
To reset the Android emulator and erase all data, open Android Studio then goes to menu Tools -> AVD Manager, then click the dropdown menu on the selected simulator and click on wipe data.
More useful cleaner scripts. Seperating modules cleaning & native cleaning, based on the other great answers:
"scripts": {
"npm:clean": "rm -rf node_modules && npm cache clean && npm install"
"yarn:clean": "rm -rf node_modules && yarn cache clean --force && yarn install"
"android:clean": "cd android && ./gradlew clean && ./gradlew cleanBuildCache && cd ..",
"ios:clean": "cd ios && xcodebuild clean && rm -rf ~/Library/Caches/CocoaPods && rm -rf Pods && rm -rf ~/Library/Developer/Xcode/DerivedData/* && pod cache clean --all && pod deintegrate && pod setup && pod install && cd ..",
}
To reset react-native specific cache, run:
npm start -- --reset-cache
if in package.json you have
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
}
I added the following scripts to my package.json
scripts: {
....
"clean:android": "echo 'require(\"child_process\").execSync(\"cd android; ./gradlew clean\", {stdio: \"inherit\"})' | node ",
"clean:ios": "echo 'require(\"child_process\").execSync(\"cd ios; xcodebuild clean\", {stdio: \"inherit\"})' | node ",
"clean": "npm run clean:android && npm run clean:ios",
....
}
now you can clean android
npm run clean:android
clean ios
npm run clean:ios
clean both
npm run clean
React and node specific cleaning:
Remove node_modules to avoid inconsitence which may appear somehow rarely:
rm -rf node_modules
(reinstall if need with npm or yarn)
Clean npm cache if npm is used
npm cache clean
Clean react temp files:
rm -rf $TMP/react*
Clean the Android Project with:
cd android/
gradlew clean
remove android folder
run
react-native upgrade
then
react-native run-android
Related
I tried to run an existing react-native project on mac to create ios build but i've been getting into an unusual error as mentioned below. I don't know what RCT-Folly does as i am new to react-native but i think the error is related to RCT-Folly, I tried many other stack answers but couldn't solve it
Here is a picture of the error
I have tried the other solution like creating a fresh projects and copying files, also tried reinstalling cocoapods,
If there is some other thread that you guys think i should try please let me know
Stuck at this for more than 3 days now!
Update:
After downgrading react native version it is now showing this error:
CompileC /Users/admin/Desktop/MTM/mindToMindfull\ 2/ios/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-Core.build/Objects-normal/x86_64/RCTJSThread.o /Users/admin/Desktop/MTM/mindToMindfull\ 2/node_modules/react-native/React/Base/RCTJSThread.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'React-Core' from project 'Pods')
RCT-Folly is an iOS Cocoapod library. Try cleaning your project first. From the project root, run (for Yarn)
watchman watch-del-all && rm -f yarn.lock; rm -rf node_modules,
then
yarn
cd ios && rm -rf ~/Library/Caches/CocoaPods Pods ~/Library/Developer/Xcode/DerivedData/; rm Podfile.lock; pod deintegrate; pod setup; pod install && cd ..
yarn ios
I haven't used npm in awhile. But for 2 and 4, use npm install and npx react-native run-ios
Solved by downgrading react-native version 0.66.4
then installing pods and build was a success.
I change my MacBook within new MacBook M1 pro and have issue an old project.
I work on old project where I use:
expo(version 40) which one is ejected and use
react-native(version ~0.63.4)
and when I try to build(command: react-native run-ios) project It return errors always, but when I make new project everything is Okay.
I don't know what is problem.
I found one solution.
Firstly I clean project and install everything again, then start building.
Commands:
watchman watch-del-all && rm -rf node_modules && rm -rf yarn.lock && rm -rf package-lock.json && yarn cache clean && yarn && cd ios && rm -rf Pods && rm -rf Podfile.lock && pod install && cd .. && cd android && ./gradlew clean && cd .. && yarn start --reset-cache
After that I start build with this command:
arch -x86_64 yarn run ios
or
arch -x86_64 react-native run-ios
How I resolved my issue, with M1 arm Mac
> arch -x86_64 expo init AwesomeProject
> cd AwesomeProject
> arch -x86_64 yarn
>arch -x86_64 yarn start
**Working :) **
Don't clean everything, removing yarn.lock and podfile.lock is not required. As this might upgrade the dependencies which might be required and would require testing.
I faced similar issues on M1 Mac. I am listing them down.
Error: GET https://github.com/electron/electron/releases/download/v1.8.8/electron-v1.8.8-darwin-arm64.zip returned 404
Solution this was to upgrade react-devtools in your package file
"react-devtools": "^4.23.0", // Upgrade to the latest one
Then make sure your paths are setup correctly. I added one additionally as it was required for me. You can update path if required as suggested below. I am using z Shell so suggesting zshrc
echo 'export PATH=/usr/bin/node:$PATH' >> ~/.zshrc
Since mine was an existing project and has x86 libs. I use Rosetta for Xcode. By right clicking on xcode => Get Info => Select Open using Rosetta.
Finally
brew install cocoapods // To install compatible arch for m1
arch -x86_64 gem install ffi. // Install the ffi Ruby gem for Apple’s Rosetta 2
arch -x86_64 pod install
arch -x86_64 yarn run ios
I'm run on IOS is error, but I'm run on android as well
Screenshort error
I'm did linking lin into project.
I do clear cache and reinstall node_modules, but it is not running.
watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf yarn.lock && rm -rf ./node_modules && yarn install && yarn start -- --reset-cache
I don't find what wrong. Please help me.
Environment
React Native Navigation version: 1.1.236
React Native version: 0.48.4
Platform(s) (iOS, Android, or both?): IOS
Device info (Simulator/Device? OS version? Debug/Release?): Simulator
In your index.js file:
import {AppRegistry} from 'react-native';
AppRegistry.registerComponent('MYAPPNAME', () => APP )
My react-native run-ios --device stuck after displaying this line.
simulator does not stuck.
I tried
`rm -rf $TMPDIR/react-* && watchman watch-del-all && rm -rf ios/build/ModuleCache/* && rm -rf node_modules/ && npm cache clean && npm i`.
No luck.
bundle: Done writing bundle output
bundle: Copying 84 asset files
bundle: Done copying assets
+ [[ ! -n false ]]
Same on using xcode build.
Xcode says running 2 of 4 custom shell scripts and report navigator displays
bundle: Done writing bundle output
bundle: Copying 84 asset files
bundle: Done copying assets
+ [[ ! -n false ]]
Any suggestion?
react-native: 0.44.0
I am new to npm build tools. I want to bundle the compiled typescript files as soon as there is a change in typescript files and run lite-server concurrently. To achieve that I have written following npm build script -
"build": "tsc",
"bundle": "browserify -s main app/goc-common/common.module.js > dist/bundle.js",
"build_dev": "npm run build && npm run bundle && concurrently \"tsc -w && npm run bundle\" \"lite-server\"",
However this doesn't seems to work, it just compiles the files and refresh the browser, donot bundle the files again.
You should use watchify to continue watching tsc's output files for changes:
"build": "tsc",
"bundle": "watchify -s main app/goc-common/common.module.js -o dist/bundle.js",
"build_dev": "npm run build && npm run bundle && concurrently \"tsc -w && npm run bundle\" \"lite-server\""
As you've noticed, browserify doesn't watch; it just runs once and then it's done. watchify's usage is identical to browserify's, except that the -o option is mandatory.