How to safely remove resolve-url? - npm

I have an npm package resolve-url in my React Native project. The package is deprecated, and I'm not using it, so I want to remove it. However, after I run npm uninstall resolve-url to uninstall per npm's documentation, my project no longer runs with npm start!
How do I safely remove resolve-url?

How do I safely remove resolve-url?
It turns out that my project depended on resolve-url through another package, source-map-resolve.
Solution:
npm uninstall source-map-resolve
npm uninstall resolve-url
I deleted the newly created package-lock.json because my project used yarn.lock.
I cleaned up remaining references to source-map-resolve and resolve-url in my yarn.lock.
More info

Related

NPM uninstalled package details still exist in package-lock.json - should I remove them?

npm uninstall react-dates --save
still leaves a lot of traces in package-lock.json - airbnb-prop-types for e.g. How do I remove them? Additionally, if it is the case that it is some other package which uses them, how do I find out which one it is?

How to prevent nested node_modules inside node_modules

I've created my own npm package, let's call it XYZ, it has #material-ui dependency in it's package.json file.
When I install it in project A I have nested node_modules inside of XYZ folder(so it's A\node_modules\XYZ\node_modules\#material-ui), but when I install it in project B I don't have nested node_modules folder. Both project A and B has #material-ui in their package.json files with same versions.
How to force my XYZ package to use #material-ui from A\node_modules?
There are upside of having less nested folders and downside having more folders in node_modules folder directly and version control problems.
Use correct npm version
Correct yarn and npm (ie: npm v3) should not have such structure issue. It should always flatten the whole structure where possible and only have nested node_modules if the versions are incompatible with the one at top.
Check versions
So if you have it working properly on one project and not on another, its probably due to version. Check out if the #material-ui is same version on both. Maybe two different packages are conflicting with each other at some point.
Check how you are installing them
From your question, it says it's same version. However, you did not mention how you installed your package on both project. If you install with yarn link or npm link it should install dependencies properly as expected.
Check if you are using different packages
If you check the package, recently material-ui has been deprecated, and the notice says to upgrade to #material-ui/core instead. It might be some packages inside that folder is not same. Either way, it's like this whenever there is some dependency conflict. Check inside the #material-ui folder.
Flatten them manually (dangerous)
There are several packages to forcefully resolve this issue. They will go thru the nested node_modules folders and flatten them into single folder.
flatten-packages
Install with, npm install -g flatten-packages.
Run executable flatten-packages to rearrange all packages in node_modules folder in the project directory.
Flatten will delete older version of a package. You should take care of version breaking changes related errors.
You can use npm dedupe command to accomplish this.
You can put the command in postinstall script in package.json, and every time NPM installs package, the npm dedupe command will flatten all the duplicated packages in same version for you.
For more information, see https://docs.npmjs.com/cli/dedupe
npm postinstall script
I had the same issue in a React Native app with my NPM package.
The problem was that in project A the version of React Native used was (0.59.5) below the version used in my package (0.59.8).
Installing the package in a brand new project (B), of course was using the latest version of React Native in that moment, that was the same of my package (0.59.8).
I have another addition to the accepted answer:
Clear Local node_modules folder Cache
rm -rf node_modules
Handle with care: Sometimes migrating projects to new npm modules can cause weird cache issues inside a node_modules folder, especially those that have been around for a while, or happened to have newer versions of packages installed in sub-dependencies that differed from the installed version in root.
Once you remove direct dependencies via the package.json dependencies, the packages will be removed from the <root>/node_modules. This can cause a bug where the new modules are still nested under your dependency instead of being moved to root as expected.
So by wiping out your local node_modules, you can do a clean reinstall and let the flattening to its work.

How do I force npm to reinstall a single package, even if the version number is the same?

In my Node.js project, I have a dependency on another local project. Oftentimes, I need to make a small change to the dependency and see how it affects my main project. In order to do this, I have to reinstall my dependency using npm.
I can use npm update to try to update my dependency, but this seems like it will only work if the version number has changed on the dependency. I don't want to have to change the version number on my dependency every time I change a line of code or two to make an experimental change in development.
I can rm -rf node_modules/; npm install to ensure that I get the latest versions of all of my dependencies. Downloading all of my non-local dependencies takes several minutes, breaking up my train of thought.
Is there a way to force npm to reinstall a single dependency, even if that dependency's version number hasn't changed?
When you run npm install, it will install any missing dependencies, so you can combine it with an uninstall like this:
npm uninstall some_module; npm install
With npm 5, uninstalled modules are removed from the package.json, so you should use:
npm uninstall some_module; npm install some_module
On npm v 6.14:
npm install module_name --force --no-save
You get a message stating:
npm WARN using --force I sure hope you know what you are doing.
And then it proceeds to uninstall and reinstall the package.
Note: if you don't specify the --no-save option, npm updates the package version on package.json to the highest version that is compatible with the existing SemVer rule.
If you do not want npm to update the package's version on package.json, keep the --no-save option.
Not the best answer, but just for information, you can run
npm ci
It is the same as npm install, but it will remove the existing node_modules folder, if any, and do a fresh install for all packages. This is useful if the files in node_modules have been changed for some reason and you want to revert them to their original state.

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

How do I delete a NPM project?

I pushed some junk code into npm. How do I delete the project? There's a better alternative. I don't have any users for my project yet.
Thanks!
Mike
From the man pages npm help unpublish:
DESCRIPTION
This removes a package version from the registry, deleting its entry
and removing the tarball.
If no version is specified, or if all versions are removed then the
root package entry is removed from the registry entirely.
The package was still there for me after npm unpublish --force.
npm info listed all the versions. npm unpublish package#x.x.x --force removed them individually. After that I checked npmjs.org and the package page said: "This package has been unpublished"