how to delete installed library form react native project

React Native

React Native Problem Overview


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 ?

React Native Solutions


Solution 1 - React Native

  1. 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
  2. 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
  3. 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

Solution 2 - React Native

I followed the following steps:--

  1. react-native unlink <lib name> -- this command has done the unlinking of the library from both platforms.

  2. react-native uninstall <lib name> -- this has uninstalled the library from the node modules and its dependencies

  3. 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

Solution 3 - React Native

If you want to unlink already installed packages in react native

  1. $ react-native unlink package_name
  2. $ 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

Solution 4 - React Native

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

Solution 5 - React Native

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.

Solution 6 - React Native

You can delete installed react native package with this command.

npm uninstall package_name

example:

npm uninstall react-native-camera

Solution 7 - React Native

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.

Solution 8 - React Native

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

Solution 9 - React Native

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.

Solution 10 - React Native

Simple and easy solution.

npm uninstall --save react-native-image-slider-box

Solution 11 - React Native

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:

  1. 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.)
  2. 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.
  3. 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:

  1. 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.
  2. 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.

  3. 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.)
  4. 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.
  5. 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!

Solution 12 - React Native

Uninstalling local packages: npm uninstall for example: npm uninstall react-native-webview

Uninstalling global packages: npm uninstall -g for example: npm uninstall -g react-native-webview

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionrajat44View Question on Stackoverflow
Solution 1 - React NativeAakash SigdelView Answer on Stackoverflow
Solution 2 - React NativeNicksView Answer on Stackoverflow
Solution 3 - React NativePiushaView Answer on Stackoverflow
Solution 4 - React NativeValdaXDView Answer on Stackoverflow
Solution 5 - React NativeIsaac CerdaView Answer on Stackoverflow
Solution 6 - React NativeBellal HossainView Answer on Stackoverflow
Solution 7 - React NativeAmir ArdalanView Answer on Stackoverflow
Solution 8 - React NativebismaView Answer on Stackoverflow
Solution 9 - React NativeShahView Answer on Stackoverflow
Solution 10 - React NativeAbdul Basit RishiView Answer on Stackoverflow
Solution 11 - React NativejaquinocodeView Answer on Stackoverflow
Solution 12 - React NativeAkanksha IngleView Answer on Stackoverflow