Command to remove node_modules and clear all watchman watches - MacOS - macos

Most of the time, I have to run a clean build of my React Native project.
Currently I'm using this command: cd android && ./gradlew clean to clean gradle.
Is there a command to clean gradle, delete node_modules and watchman watches?

try to run the following command inside the terminal of your project's root directory.
watchman watch-del-all && rm -rf node_modules/ && yarn install && react-native start --reset-cache"

Related

NPM error while trying to make a auth system using Laravel Breeze

When I run npm install, I'm getting the following error:
How can I solve this?
Update your node.js to the latest
make sure that the node version is up to date by running:
$ node -v
in your CMD and by visiting
https://nodejs.org/en/download/current/
To know what is the latest version.
run this command in your CMD:
$ npm cache clean --force
then Delete node_modules by running:
$ rmdir /S /Q node_modules
or delete it manually by going into the directory and right-click > delete / move to trash. If you are not updating your packages you can delete the package-lock.json file too.
now you can run:
$ npm install
This works for me, all the best.

How to uninstall Yarn from a project

I'm a bit confused.
I accidentally installed yarn in a project. I just ran the command yarn that installed the yarn in the project. How do I uninstall yarn from the project?
Do I type in npm uninstall yarn? to uninstall it from a project?
I looked at other solutions and I'm confused.
Run npm uninstall yarn make sure it no longer is listed in your package.json
Delete the yarn.lock file if there is one
If in linux (similar for others I guess):
cd project_directory
Run "npm uninstall yarn"
rm -rf .yarn
rm .yarnrc.yml
rm yarn.lock
in package.json: delete "yarn" lines
in .gitignore (if present): delete "yarn" lines
in README.md (if present): change "yarn" to "npm"
run "grep -irl yarn ." to find any other references

reduce docker build time for react static app

I trying to reduce the time take to build a docker image to react app,
the react should be static without server rendering.
now it takes around 5-10 minute to create an image and the image size on the local machine is around 1.5GB !!, the issue is that also after the second time of image creation, even I changed smth in the code it doesn't use any cache
I am looking for a solution to cut the time the size and here is my docker File after lot of changes
# Producation and dev build
FROM node:14.2.0-alpine3.10 AS test1
RUN apk update
RUN apk add \
build-base \
libtool \
autoconf \
automake \
jq \
openssh \
libexecinfo-dev
ADD package.json package-lock.json /app/
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
ADD . /app/
RUN rm -rf node_modules
RUN npm install --production
# copy production node_modules aside, to prevent collecting them
RUN cp -R node_modules prod_node_modules
# install ALL node_modules, including 'devDependencies'
RUN npm install
RUN npm install react-scripts#3.4.1 -g --silent
RUN npm run build
RUN rm -rf node_modules
RUN cp -R prod_node_modules node_modules
#FROM node:13.14.0
FROM test1
# copy app sources
COPY --from=test1 /app/build .
COPY --from=test1 /app/env-config.js .
# serve is what we use to run the web application
RUN npm install -g serve
# remove the sources & other needless stuff
RUN rm -rf ./src
RUN rm -rf ./prod_node_modules
# Add bash
RUN apk add --no-cache bash
CMD ["/bin/bash", "-c", "serve -s build"]
You're hitting two basic dynamics here. The first is that your image contains a pretty large amount of build-time content, including at least some parts of a C toolchain; since your run-time "stage" is built FROM the build stage as is, it brings all of the build toolchain along with it. The second is that each RUN command produces a new Docker layer with differences from the previous layer, so RUN commands only make the container larger. More specifically RUN rm -rf ... makes the image slightly larger and does not result in space savings.
You can use a multi-stage build to improve this. Each FROM line causes docker build to start over from some specified base image, and you can COPY --from=... previous build stages. I'd do this in two stages, a first stage that builds the application and a second stage that runs it.
# Build stage:
FROM node:14.2.0-alpine3.10 AS build
# Install OS-level dependencies (including C toolchain)
RUN apk update \
&& apk add \
build-base \
libtool \
autoconf \
automake \
jq \
openssh \
libexecinfo-dev
# set working directory
WORKDIR /app
# install app dependencies
# (copy _just_ the package.json here so Docker layer caching works)
COPY package.json package-lock.json ./
RUN npm install
# build the application
COPY . ./
RUN npm run build
# Final stage:
FROM node:14.2.0-alpine3.10
# set working directory
WORKDIR /app
# install dependencies
COPY package.json package-lock.json ./
RUN npm install --production
# get the build tree
COPY --from=build /app/build/ ./build/
# explain how to run the application
ENTRYPOINT ["npx"]
CMD ["serve", "-g", "build"]
Note that when we get to the second stage, we run npm install --production on a clean Node installation; we don't try to shuffle back and forth between dev and prod dependencies. Rather than trying to RUN rm -rf src, we just don't COPY it into the final image.
This also requires making sure you have a .dockerignore file that contains node_modules (which will reduce build times and avoid some potential conflicts; RUN npm install will recreate it in the directory). If you need react-scripts or serve those should be listed in your package.json file.

How Can I Solve Permission Denied in React Native Project?

anyone faced this issue after a run
react-native run-android/ios
android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java
(Permission denied)
when i write sudo before any command like npm install/yarn add etc it's work very well
otherways i got errors related to Permission
You might check the permissions on android/gradlew
They should be 755 not 644
Run chmod 755 android/gradlew inside your app root folder
then run react-native run-android
And it should work again
Finally remove the node modules and re-install using rm -rf node_modules && npm install
It looks like you have no permission- try this
sudo chmod -R 777 {path}
deleting node_modules folder from project and then running command npm i worked for me in existing react-native project

How to delete Node_modules folder in command line on Windows?

So, I should delete all node_modules in my project(I want that the node_modules folder become completely empty). Just removing folder manually does not suit me.
I read that I can delete it with rm -rf node_modules/ BUT it does not work on WINDOWS.
How to delete it?
Deleting node_modules is as simple as writing the node_modules without a slash:
rm -rf node_modules
rm -rf node_modules shouldn't have a slash at the end /, and this worked for me even on Widows.
Installing globally rimraf will do the job.
npm install -g rimraf
From the docs:
If installed with npm install rimraf -g it can be used as a global
command rimraf [ ...] which is useful for cross platform
support.
So with installing this package, you can remove directories on all platforms(windows, linux).
All left to do is rimraf node_modules

Resources