Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install npm package without dependencies

I am looking for best solution how to install npm package without it's dependencies described in it's package.json file.

The goal is to change dependencies versions before install package. I can do it manually for one package by downloading source, but if you have many nested dependencies it becomes a problem.

like image 683
Cyprian Gepfert Avatar asked Feb 07 '15 13:02

Cyprian Gepfert


People also ask

Does npm install install optional dependencies?

Use npm ci to install all dependencies, including optional dependencies (e.g. on your development environment).

How do I remove dependency?

A dev dependency is a package used during development only. To remove a dev dependency, you need to attach the -D or --save-dev flag to the npm uninstall, and then specify the name of the package. You must run the command in the directory (folder) where the dependency is located.

Can I install NPM packages offline?

The method described here is to package the dependencies into a tar file, then on the isolated environment, one can use the npm install <your tar file> command to install dependencies file without internet connection.


2 Answers

Here's a shell script that seems to get you the extracted files you need.

#!/bin/bash
package="$1"
version=$(npm show ${package} version)
archive="${package}-${version}.tgz"
curl --silent --remote-name \
  "https://registry.npmjs.org/${package}/-/${archive}"
mkdir "${package}"
tar xzf "${archive}" --strip-components 1 -C "${package}"
rm "${archive}"

Save it as npm_download.sh and run it with the name of the package you want:

./npm_download.sh pathval

like image 76
Peter Lyons Avatar answered Oct 18 '22 02:10

Peter Lyons


Please check simialr quesition on stackexchange: https://unix.stackexchange.com/questions/168034/is-there-an-option-to-install-an-npm-package-without-dependencies

My solution was to rename package.json to package.bak before the install, then reverting rename afterwards:

RENAME package.json package.bak
npm install <package_name> --no-save
RENAME package.bak package.json
like image 2
Vitaliy Ulantikov Avatar answered Oct 18 '22 01:10

Vitaliy Ulantikov