jayhendren
jayhendren

Reputation: 4511

`npm install` installs all dependencies of my project over the network, even if they are already installed or available from cache

whenever I run npm install in my project directory, npm fetches and installs all dependencies even if they're already installed in node_modules. Npm does not install from my cache in ~/.npm/, even though there are already an extremely large number of packages in my cache.

Here is my npm config settings from npm config ls -l:

; cli configs
long = true
registry = "https://registry.npmjs.org/"

; userconfig /Users/jay/.npmrc
username = "jayhendren"

; globalconfig /Users/jay/local/nodejs/etc/npmrc
global = true
globalconfig = "/Users/jay/local/nodejs/etc/npmrc"
globalignorefile = "/Users/jay/local/nodejs/etc/npmignore"
prefix = "/Users/jay/local/nodejs"

; default values
always-auth = false
bin-links = true
browser = null
ca = null
cache = "/Users/jay/.npm"
cache-lock-retries = 10
cache-lock-stale = 60000
cache-lock-wait = 10000
cache-max = null
cache-min = 10
cert = null
color = true
depth = null
description = true
dev = false
editor = "/usr/bin/vim"
; email = "" (overridden)
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
force = false
git = "git"
git-tag-version = true
group = 20
heading = "npm"
https-proxy = null
ignore-scripts = false
init-module = "/Users/jay/.npm-init.js"
init.author.email = ""
init.author.name = ""
init.author.url = ""
init.license = "ISC"
json = false
key = null
link = false
local-address = undefined
loglevel = "http"
; long = false (overridden)
message = "%s"
node-version = "v0.10.25"
npat = false
onload-script = false
optional = true
parseable = false
production = false
proprietary-attribs = true
proxy = null
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
rollback = true
save = false
save-bundle = false
save-dev = false
save-optional = false
searchexclude = null
searchopts = ""
searchsort = "name"
shell = "/bin/zsh"
shrinkwrap = true
sign-git-tag = false
strict-ssl = true
tag = "latest"
tmp = "/var/folders/sq/ls98jmdd09l__xwpxq3qqmpw0000gn/T/"
umask = 18
unicode = true
unsafe-perm = true
usage = false
user = "nobody"
user-agent = "node/v0.10.25 darwin x64"
userconfig = "/Users/jay/.npmrc"
; username = "" (overridden)
version = false
versions = false
viewer = "man"

Does anybody know why npm insists on fetching new packages over and over and over again?

Upvotes: 16

Views: 5358

Answers (3)

Daijirō Wachi
Daijirō Wachi

Reputation: 176

Use the prefer-offline flag to install packages from cache if available and download otherwise like the following:

$ npm --prefer-offline install

See the documentation.

Upvotes: 4

Paul Sweatte
Paul Sweatte

Reputation: 24617

Use a combination of flags to emulate skip-installed

global = false
link = true
foo
+-- node_modules
    +-- blerg (1.2.5) <---[A]
    +-- bar (1.2.3) <---[B]
    |   `-- node_modules
    |       +-- baz (2.0.2) <---[C]
    |       |   `-- node_modules
    |       |       `-- quux (3.2.0)
    |       `-- asdf (2.3.4)
    `-- baz (1.2.3) <---[D]
        `-- node_modules
            `-- quux (3.2.0) <---[E]

References

npm 1.0:link

npm 1.0:Global vs Local installation

npm-folders

node.js global objects

Upvotes: 0

sanjivchristopher
sanjivchristopher

Reputation: 74

I ran "npm prune" inside my project, to remove unnecessary packages (i.e., that were not dependencies, and give you that irritating "extraneous" error message). One side effect seemed to be to remove the kind of redundant package you are talking about. For example, gulp requires the gulp-util package. Since that was already at the "top" level, it was removed from gulp's own node-modules.

Upvotes: -1

Related Questions