how to delete installed library form react native project
Asked Answered
A

12

121

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 ?

Apollo answered 27/7, 2016 at 13:3 Comment(1)
Without actually knowing how have you installed this 3rd party library, I think these two commands are likely to help you npm uninstall <package> (usually with flag --save or --save-dev) and rnpm unlink <package>Probe
A
205
  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

Amiraamis answered 27/7, 2016 at 16:19 Comment(6)
how to unlink library only one platform ?Longplaying
@SameeraChathuranga are you able to unlink library on specific platform?Bettencourt
@SameeraChathuranga you would need to remove it from the info.plist or the MainAcitivity.java (might be MainApplication.java) depending on which platform you want to unlink from. if it is iOS, run a pod install again afterwardAbstractionist
Can you switch step 1 and step 2 on this? It seems to make more sense to read step 2 before reading step 1.Orfinger
i think the order matters. Unlink first before uninstalling lest you get an error as such Cannot find module /path/to/moduleRegurgitation
what about auto-link? does the npm uninstall or yarn remove also auto-unlink?Woodward
A
104

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

Alloy answered 22/2, 2017 at 1:22 Comment(3)
how to unlink library only one platform ?Longplaying
Instead of manually removing the library from package.json and the node_modules folder, you can just use npm uninstall <lib name> as step 3.Octavo
Here are the missing steps & changes your post needs to have: 1) Step 4 should be running npx pod-install which will make sure your pods are up to date with your npm packages. 2) You shouldn't need to delete an empty library folder from the node_modules folder. Instead, you should run npm install or yarn install, which will update your node_modules folder so that it doesn't have any leftover unneeded files/folders. That should be step 5 (and I've already noted step 4). And even then step 5 should be optional since step 2 should already do this for you.Mathieu
G
18

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

Genia answered 28/6, 2018 at 19:2 Comment(0)
D
15

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

Divergency answered 4/3, 2019 at 14:51 Comment(0)
M
9

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.

Macdougall answered 12/6, 2019 at 1:6 Comment(3)
Thank you Isaac. You just gave me a whole new thing to learn about react-native, and I must say, it is an important one. Thank you very much :)Imaginary
Remember to put npx before react-native to comply with best practices. So npx react-native uninstall react-native-vector-iconsMathieu
And also run npx pod-install after running the react-native uninstall command. npx pod-install will re-install your pods (it basically just runs pod install w/o having to be inside the /ios folder), so that way your pods are up to date with your npm dependencies.Mathieu
R
3

You can delete installed react native package with this command.

npm uninstall package_name

example:

npm uninstall react-native-camera
Roye answered 7/4, 2021 at 11:11 Comment(0)
B
2

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.

Became answered 27/8, 2021 at 5:38 Comment(0)
I
1

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

Idaliaidalina answered 7/4, 2021 at 13:8 Comment(2)
This will work, but you can omit the delete step in most cases.Became
This is not recomended, simply type npm uninstall --save package_nameOverstuffed
M
1

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!

Mathieu answered 9/1, 2022 at 0:22 Comment(0)
Y
0

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.

Yusuk answered 4/6, 2020 at 14:11 Comment(0)
O
0

Simple and easy solution.

npm uninstall --save react-native-image-slider-box
Overstuffed answered 6/12, 2021 at 13:48 Comment(0)
W
0

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

Wendall answered 13/1, 2022 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.