how do i add yarn package to react native project installed with npm? - react-native

Note: Do guide me if something is missing.
So, I wanted to install a package from https://rnfirebase.io/auth/usage, but I have an npm project. The command on the website has only for yarn. I don't want to add yarn to project because (Is there any harm in using NPM and Yarn in the same project?) it states that it is not recommended.
So, then how do I install it with npm?

You have to use yarn, or you can look for a package that has the functions that you are looking for using npm

You can install it with npm just fine, don't worry. They are all package managers installing npm packages from the same repository. There is no difference in what you are installing or how they are installed. You can get different node_module structures, but for yarn you need config for that.
Yes its not recommended because it generates different lockfiles that will dictate different structures and versions in your node_modules folder. You want multiples devs to have the same "experience". However, lots of JS frameworks will come pre-configured with yarn, like React Native and you just end up having two lockfiles. One for npm and one for yarn. There is no harm in deleting the yarn file and keeping the package-lock. If you delete both, a new lockfile for the package manager you are using will be generated on npm i | yarn i | pnpm anyway.
To install it with npm just use npm i <PACKAGE_NAME> so npm i #react-native-firebase/app.
Here is the npm repo page for that package, https://www.npmjs.com/package/#react-native-firebase/app, notice the install command is npm! Only reason firebase devs only mention yarn is because they are hipsters ;)

Related

npm start install my package, but i'm running my project with yarn start

If I installed some package with NPM it will work and recognize it if I run my project with yarn start instead npm start?
Yes, it will still work after all the required packages are installed.
But you should not switch package Managers like that since you will generate two lock files if you use both to install packages. npm generates the package-lock.json and yarn will generate the yarn.lock file. I recommend you to stay with one or switch completely.
In runtime, it does not make any difference if you use yarn or npm.
npm run start and yarn start will do exactly the same.

Globally installation of packages with npm

I have a question regarding the package manager npm and the meaning of installing the package globally.
For example I work often with react, should I install react globally?
npm install -g react react-dom
Does this mean that next time when I do
npx creat-react-app my-app
It will get the package from the global or it does not matter and it will still download it locally inside my-app?
Because I really do not understand the idea behind installing globally.
Because if I want to use a package it should be mentioned in package.json, if it is in package.json it is then located in node_module ... so yeah ...
Could anyone give me better insight?
Thanks in advance
React library can be installed globally on your local machine. In development there is no real reason to do that since you might not have the latest version and this might cause issues.
Better practise is to use react on project level by using the command you stated above npx create-react-app my-app
If you push code to a server the package.json file will install the dependencies (React, React DOM,..) to build your project.
Read more here : https://create-react-app.dev/docs/getting-started/
If you've previously installed create-react-app globally via npm
install -g create-react-app, we recommend you uninstall the package
using npm uninstall -g create-react-app or yarn global remove
create-react-app to ensure that npx always uses the latest version.
You can check what packages are installed globally using:
npm list -g --depth 0

React-native-maps failed to install

I am new to react-native and I want to install react-native-maps. However whenever I run npm install react-native-maps --save in the project folder, the project breaks with node_modules/react-native become empty with only an empty folder node_modules inside. I am following the installation guide from the official github now and using react-native 0.55.3.
Below attached with a dump when I call npm install react-native-maps --save:
screen_dump: react-native-maps install failure:
There is a known issue which is fixed with v5.7.0 (As far as I know. Didn't try it myself).
After updating your npm to a newer version, you should delete node_modules and do a clean install with npm install to reinstall all necessary packages.
One other option is to use yarn. I think it is a little better tool for package management. (Personal preference. You don't have to use it). If you decide to use yarn, you should still delete node_modules and do a clean install with yarn install
Install yarn package manager from the following link
enter link description here
Use following command to install the package.
yarn add react-native-maps
This might be works. Yarn packager is better than npm for me.

What is the difference between brew, yarn, and npm?

I was using the react-native package which I installed globally with npm. Now it says at the first line after executing the init command. The following:
Installing react-native from npm...
Consider installing yarn to make this faster: https://yarnpkg.com
So I was checking that website and it looked interesting to me, but I don't exactly know what it would be. At first, I thought that I would need brew to install yarn, so I could yarn to install npm. But now I think that yarn is a replacement of npm. Is that a correct statement?
Why would I like to have so many package managers?
I understand that it's useful for software like Atom or Visual Studio Code to have their own package manager. But for development, I do not see the reason why someone would like to use four different package managers (brew for 'primary software', yarn for npm packages, npm for backend modules and bower for front-end libraries). How can this package manager forest be untangled?
I am not familiar with brew, but I suppose you mean the Homebrew software package management system for macOS.
Then the purpose of each system is:
brew: installation of software, i.e. ready to consume applications like wget.
npm: installation of packages (libraries), i.e. pieces of functionality to help you build your own applications.
yarn: also installation of packages.
Yarn has some advantages over npm, the main two are the speed and the predictability. Yarn reuses the npm's package.json file and doesn't change its structure. Therefore you can run yarn install instead of npm install and theoretically everything will work automatically.
P.S. I agree, https://yarnpkg.com doesn't have enough background on why the hell we need another package management system, but there is a great article which fills that gap.
yarn vs npm
yarn and npm are both manage module installations and dependencies. Yarn was built to address some of the shortcomings of npm.
The biggest advantages of yarn over npm are
Installing packages with yarn is parallelized and so package installation is faster.
package.json can be very loose in terms of version numbers. yarn.lock (similar to npm shirkwrap) locks this down so that two machines with the same package.json always install the exact same packages.
yarn allows you to check why some packages are installed (understand the dependency tree)
Ref: https://www.sitepoint.com/yarn-vs-npm/
Yarn is a JavaScript package manager built by Facebook, Google, Exponent, and Tilde. It is created to remove or overcome the features that lack in npm. In comparison with npm it has
Enhanced Security
Offline mode
Parallel Installation - Therefore, faster installation
Another major difference was the yarn.lock file, but after npm ^5.x.x they provide the package-lock.json file too.
And the commands of yarn works like npm:
# Starting a new project
npm init === yarn init
# Installing all the dependencies of the project
npm install === yarn or yarn install
# Adding a dependency
npm install [package] === yarn add [package] # The package is saved to your package.json immediately.
npm install [package]#[version] === yarn add [package]#[version]
npm install [package]#[tag] === yarn add [package]#[tag]
# Add a dev dependency
npm install [package] --save-dev === yarn add [package] --dev
# Upgrading a dependency
npm update [package] === yarn upgrade [package]
npm update [package]#[version] === yarn upgrade [package]#[version]
npm update [package]#[tag] === yarn upgrade [package]#[tag]
# Removing a dependency
npm uninstall [package] === yarn remove [package]
# View registry information
npm view [package] === yarn info [package]
# List installed packages
npm list === yarn list
npm list --depth === yarn list --depth=0
# Install packages globally
npm install -g [package] === yarn global addb [package]
# Run a defined package script
npm run [script] === yarn run [script]
Refferences
https://www.sitepoint.com/yarn-vs-npm/
https://scotch.io/#brian_kimo/npm-vs-yarn
and the official announcement
https://code.facebook.com/posts/1840075619545360
Yarn is, like NPM, a package manager for Node.JS.
Yarn is built by Facebook.
It's faster and has more features than NPM.
Their main selling points are:
Security With yarn.lock file (similar to NPM's npm-shrinkwrap.json)
all dependencies are locked on the exact version. So, you don't have that “But it works on my machine” struggles anymore. Everyone has the
same versions locked in yarn.lock file
Speed Yarn uses (fast) proxies and (offline) caching to deliver your
modules faster. It also has a LICENSE checker, which checks the
license of all your dependency modules.

how to delete installed library form react native project

I have installed a third party library in my project but it is not working , so I want to delete that library from my project ,
How can I do that ?
If it is a library based only on javascript, than you can just run npm uninstall --save package_name or npm uninstall --save-dev package_name
If you've installed a library with native content that requires linking, and you've linked it with rnpm then you can do: rnpm unlink package_name then follow step 1
If you've installed a library with native content manually, then just undo all the steps you took to add the library in the first place. Then follow step 1.
note rnpm as is deprecated
I followed the following steps:--
react-native unlink <lib name> -- this command has done the unlinking of the library from both platforms.
react-native uninstall <lib name> -- this has uninstalled the library from the node modules and its dependencies
Manually removed the library name from package.json -- somehow the --save command was not working for me to remove the library declaration from package.json.
After this I have manually deleted the empty react-native library from the node_modules folder
If you want to unlink already installed packages in react native
$ react-native unlink package_name
$ yarn remove package_name (if it is npm then npm uninstall --save)
If you execute 2nd step before 1st step you need to install relevant package back and execute 2nd step
I will post my answer here since it's the first result in google's search
1) react-native unlink <Module Name>
2) npm unlink <Module Name>
3) npm uninstall --save <Module name
From react-native --help
uninstall [options] uninstall and unlink native dependencies
Ex:
react-native uninstall react-native-vector-icons
It will uninstall and unlink its dependencies.
You can delete installed react native package with this command.
npm uninstall package_name
example:
npm uninstall react-native-camera
remove package name from package.json file
delete package-lock.json file
then run npm install
or you can run the following command to uninstall any package
npm uninstall package_name
you have to check your linked project, in the new version of RN, don't need to link if you linked it cause a problem,
I Fixed the problem by unlinked manually the dependency that I linked and re-run.
For iOS...
Remove the node package and install the pods.
If you're using npm:
npm uninstall package-name
If you're using yarn:
yarn remove package-name
Then simply install pods with:
npx pod-install
Typically the package.json directory is in the root of your project folder, so you should run these from there. npx pod-install will go to your ios folder and will run pod install. You do not need to run this step if you are not adding/removing native components.
I think for Android it might be the same steps, but without running the latter command since Android does not use cocoapods.
Simple and easy solution.
npm uninstall --save react-native-image-slider-box
All of the top answers are a bit outdated. They do work, but the process could be better. So I'm going to post a more modern and 'normal' way.
Assumptions:
Your project is not overly old, meaning that your project is not using react-native version <0.60 (less than 0.60). This is because in the past (when you had react-native version <0.60), you had to manually run commands like react-native unlink when you wanted to uninstall a package. Those commands still work but are no longer necessary.
The library/package works with autolinking or it doesn't need linking at all because the package doesn't use native code. If the package's installation instructions don't require you to run a command to link the package (e.g. react-native link), then it uses autolinking or it doesn't need linking at all. A package might suggest you run the link command but they'll also usually say it's not required if your project's react-native is version >=0.60. The majority of libraries are like this now. I'd be surprised if the package you want to uninstall uses native code but doesn't support autolinking. Read more about autolinking.
If the package you want to uninstall doesn't use native code, then the above paragraph about autolinking doesn't matter.
You of course remembered to remove any use of the package in your project, before you try to uninstall it.
You've checked if other packages require the package you want to delete as a peer dependency. In this case, you removing that dependency can cause your other packages to not work.
If your package was installed without any manual editing of native files (e.g. android/settings.gradle, ios/yourappname/AppDelegate.m, etc.) or any other configuration (e.g. mypackage.config.js), then you should just do this:
If using npm, run npm uninstall <yourpackage>. If using yarn, run yarn remove <yourpackage>.
(React native uses autolinking to unlink the packages automatically so this is all you should need to do to 'unlink'. Read more.)
Run cd ios && pod install && cd ..
You can skip this step if you're absolutely sure that the package is purely written in JavaScript/Typescript. My opinion is to just run it anyway so that way your brain doesn't have to spend energy thinking/worrying about this.
That's it. You're good to go. If you're not good to go here, then something is very wrong.
If you did have to manually edit native files or any other extra configuration to install your package, then:
It's a good idea to get all the info you can on what you exactly did when you installed the package. Any additional context you can learn is good.
You should look at your git history to see the changes you did when you installed the package.
It's a good idea to read the package's README or docs to remind you of anything else you might have forgotten.
In addition to the package's most up-to-date README or docs, it's a good idea to try to read the package's README/docs from the exact version that you're trying to uninstall. If you just read the README from the package's main github page, for example, then the info might be too new.
Undo the manual changes you did when installing the package. Ideally, use git diff or a git GUI program to help you out with this. Because this process varies depending on the package and what you actually did, it's hard to be more specific than that.
If using npm, run npm uninstall <yourpackage>. If using yarn, run yarn remove <yourpackage>.
(React native uses autolinking to unlink the packages automatically so this is all you should need to do to 'unlink'. Read more.)
Run cd ios && pod install && cd ..
You can skip this step if you're absolutely sure that the package is purely written in JavaScript/Typescript. My opinion is to just run it anyway so that way your brain doesn't have to spend energy thinking/worrying about this.
That's it, done. If things are not good at this point, then something is very wrong.
Remember to upvote if you feel this helped you, so it can be more visible. Thanks!
Uninstalling local packages:
npm uninstall <package_name>
for example:
npm uninstall react-native-webview
Uninstalling global packages:
npm uninstall -g <package_name>
for example:
npm uninstall -g react-native-webview