[FIXED] Does npm install have an equivalent to pip install –no-deps?

Issue

I’m more familiar with the Python ecosystem at this point and have a question about how I can do something with npm that I’m used to doing with pip.

Let’s say I have a wheel for a particular Python package, as well as a wheel file for each of the Python package’s dependencies. And let’s say I have all these wheel files in a folder called /path/to/wheel/files. To install this package and all of its dependencies, I could run something like pip install /path/to/wheel/files/*.whl --no-deps, where --no-deps keeps me from having to install the various dependencies in the proper order.

Does npm have an equivalent to this? I’m using npm-offline-packager to create a tarball that contains a Node package (as its own tarball) and all of its dependencies (as their own tarballs). I know I can tell npm install to install a particular tarball. However, when I do this, it tries pulling in the required dependencies from the online NPM registry instead of pulling in the dependencies from the tarballs I already have.

Ideally, I’d like npm install to use the tarballs to add the main package to my project’s package.json while adding the package’s dependencies to my project’s package-lock.json. And of course, I’d also like the main package and all its dependencies to be installed to my project’s node_modules directory as well.

TL;DR Does npm have something equivalent to pip install /path/to/wheel/files/*.whl --no-deps?

Solution

I’m responding to my own question here, but note that my answer is only applicable to my particular use case and may not be applicable in general.

For my use case, I have access to two computers: one that has access to the internet and one that doesn’t. For the machine that doesn’t have access to the internet, I was attempting to use Verdaccio as a way of creating a self-hosted NPM registry. However, publishing packages to Verdaccio wasn’t working because it kept trying to pull in the package’s dependencies from the public NPM repository. The solution was to remove all references to "npmjs" in Verdaccio’s config file (which, for me, Verdaccio created at ~/.config/verdaccio/config.yaml).

So, in case anyone needs to do development on a machine that doesn’t have access to the internet, the process for setting up Verdaccio looks something like this:

  1. On the machine that has access to the internet, create an NPM project using npm init (I called my project "verdaccio_runner"). The reason I did this is because, without already having an NPM registry on the machine that doesn’t have access to the internet, it was hard doing a global install of Verdaccio.
  2. Run npm install verdaccio to install Verdaccio to the NPM project that was created in the previous step.
  3. Transfer this project over to the machine that doesn’t have access to the internet.
  4. Once it’s transferred over, run Verdaccio from the project like this: npx verdaccio.
  5. Quit out of Verdaccio.
  6. Remove all references to "npmjs" from the config file that Verdaccio created (again, mine was at ~/.config/verdaccio/config.yaml).
  7. Run Verdaccio again to pull in those changes.
  8. Tell NPM where your private registry is: npm config set registry http://localhost:4873/.
  9. Add yourself as a user by running npm adduser and by then filling out the information you’re prompted for.

And the process for publishing packages to Verdaccio on a machine that doesn’t have access to the internet looks like this:

  1. For the package you want to install, on the machine that has access to the internet, run npo fetch <package name> --no-cache (assuming you’ve already done a global install of npm-offline-packager on the machine that has internet access).
  2. Bring the tarball that npo created for you over to the machine that doesn’t have internet access.
  3. Untar the tarball.
  4. From the directory that’s created, run for file in ./*.tgz; do npm publish $file; done.
  5. The published packages can now be npm installed to projects on the machine that doesn’t have internet access.

Note: in order for Verdaccio to be accessible to other machines on the private network, I also had to add the following to Verdaccio’s config file:

listen:
  0.0.0.0:4873

Answered By – Caleb Koch

Answer Checked By – David Goodson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published