Skip to content

Commit 74c9975

Browse files
committed
fix(docs): add npm update example
Adds an example of when `npm update` would not install the latest version of a package because other subdependencies in your tree have tighter restrictions. PR-URL: #3494 Credit: @wraithgar Close: #3494 Reviewed-by: @lukekarrys
1 parent 4755b07 commit 74c9975

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

docs/content/commands/npm-update.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ aliases: up, upgrade
1515
### Description
1616

1717
This command will update all the packages listed to the latest version
18-
(specified by the `tag` config), respecting semver.
18+
(specified by the `tag` config), respecting the semver constraints of
19+
both your package and its dependencies (if they also require the same
20+
package).
1921

2022
It will also install missing packages.
2123

@@ -101,6 +103,39 @@ Then `npm update` will install `[email protected]`, because that is the highest-sorting
101103
version that satisfies `^0.4.0` (`>= 0.4.0 <0.5.0`)
102104

103105

106+
#### Subdependencies
107+
108+
Suppose your app now also has a dependency on `dep2`
109+
110+
```json
111+
{
112+
"name": "my-app",
113+
"dependencies": {
114+
"dep1": "^1.0.0",
115+
"dep2": "1.0.0"
116+
}
117+
}
118+
```
119+
120+
and `dep2` itself depends on this limited range of `dep1`
121+
122+
```json
123+
{
124+
"name": "dep2",
125+
"dependencies": {
126+
"dep1": "~1.1.1"
127+
}
128+
}
129+
```
130+
131+
Then `npm update` will install `[email protected]` because that is the highest
132+
version that `dep2` allows. npm will prioritize having a single version
133+
of `dep1` in your tree rather than two when that single version can
134+
satisfy the semver requirements of multiple dependencies in your tree.
135+
In this case if you really did need your package to use a newer version
136+
you would need to use `npm install`.
137+
138+
104139
#### Updating Globally-Installed Packages
105140

106141
`npm update -g` will apply the `update` action to each globally installed

0 commit comments

Comments
 (0)