1NPM-CI(1) NPM-CI(1)
2
3
4
6 npm-ci - Clean install a project
7
8 Synopsis
9 npm ci
10
11 aliases: clean-install, ic, install-clean, isntall-clean
12
13 Description
14 This command is similar to npm help install, except it's meant to be
15 used in automated environments such as test platforms, continuous inte‐
16 gration, and deployment -- or any situation where you want to make sure
17 you're doing a clean install of your dependencies.
18
19 The main differences between using npm install and npm ci are:
20
21 • The project must have an existing package-lock.json or npm-
22 shrinkwrap.json.
23
24 • If dependencies in the package lock do not match those in pack‐
25 age.json, npm ci will exit with an error, instead of updating the
26 package lock.
27
28 • npm ci can only install entire projects at a time: individual de‐
29 pendencies cannot be added with this command.
30
31 • If a node_modules is already present, it will be automatically re‐
32 moved before npm ci begins its install.
33
34 • It will never write to package.json or any of the package-locks:
35 installs are essentially frozen.
36
37
38 NOTE: If you create your package-lock.json file by running npm install
39 with flags that can affect the shape of your dependency tree, such as
40 --legacy-peer-deps or --install-links, you must provide the same flags
41 to npm ci or you are likely to encounter errors. An easy way to do this
42 is to run, for example, npm config set legacy-peer-deps=true --loca‐
43 tion=project and commit the .npmrc file to your repo.
44
45 Example
46 Make sure you have a package-lock and an up-to-date install:
47
48 $ cd ./my/npm/project
49 $ npm install
50 added 154 packages in 10s
51 $ ls | grep package-lock
52
53 Run npm ci in that project
54
55 $ npm ci
56 added 154 packages in 5s
57
58 Configure Travis CI to build using npm ci instead of npm install:
59
60 # .travis.yml
61 install:
62 - npm ci
63 # keep the npm cache around to speed up installs
64 cache:
65 directories:
66 - "$HOME/.npm"
67
68 Configuration
69 install-strategy
70 • Default: "hoisted"
71
72 • Type: "hoisted", "nested", "shallow", or "linked"
73
74
75 Sets the strategy for installing packages in node_modules. hoisted (de‐
76 fault): Install non-duplicated in top-level, and duplicated as neces‐
77 sary within directory structure. nested: (formerly --legacy-bundling)
78 install in place, no hoisting. shallow (formerly --global-style) only
79 install direct deps at top-level. linked: (experimental) install in
80 node_modules/.store, link in place, unhoisted.
81
82 legacy-bundling
83 • Default: false
84
85 • Type: Boolean
86
87 • DEPRECATED: This option has been deprecated in favor of --install-
88 strategy=nested
89
90
91 Instead of hoisting package installs in node_modules, install packages
92 in the same manner that they are depended on. This may cause very deep
93 directory structures and duplicate package installs as there is no de-
94 duplicating. Sets --install-strategy=nested.
95
96 global-style
97 • Default: false
98
99 • Type: Boolean
100
101 • DEPRECATED: This option has been deprecated in favor of --install-
102 strategy=shallow
103
104
105 Only install direct dependencies in the top level node_modules, but
106 hoist on deeper dependencies. Sets --install-strategy=shallow.
107
108 omit
109 • Default: 'dev' if the NODE_ENV environment variable is set to 'pro‐
110 duction', otherwise empty.
111
112 • Type: "dev", "optional", or "peer" (can be set multiple times)
113
114
115 Dependency types to omit from the installation tree on disk.
116
117 Note that these dependencies are still resolved and added to the pack‐
118 age-lock.json or npm-shrinkwrap.json file. They are just not physically
119 installed on disk.
120
121 If a package type appears in both the --include and --omit lists, then
122 it will be included.
123
124 If the resulting omit list includes 'dev', then the NODE_ENV environ‐
125 ment variable will be set to 'production' for all lifecycle scripts.
126
127 include
128 • Default:
129
130 • Type: "prod", "dev", "optional", or "peer" (can be set multiple
131 times)
132
133
134 Option that allows for defining which types of dependencies to install.
135
136 This is the inverse of --omit=<type>.
137
138 Dependency types specified in --include will not be omitted, regardless
139 of the order in which omit/include are specified on the command-line.
140
141 strict-peer-deps
142 • Default: false
143
144 • Type: Boolean
145
146
147 If set to true, and --legacy-peer-deps is not set, then any conflicting
148 peerDependencies will be treated as an install failure, even if npm
149 could reasonably guess the appropriate resolution based on non-peer de‐
150 pendency relationships.
151
152 By default, conflicting peerDependencies deep in the dependency graph
153 will be resolved using the nearest non-peer dependency specification,
154 even if doing so will result in some packages receiving a peer depen‐
155 dency outside the range set in their package's peerDependencies object.
156
157 When such an override is performed, a warning is printed, explaining
158 the conflict and the packages involved. If --strict-peer-deps is set,
159 then this warning is treated as a failure.
160
161 foreground-scripts
162 • Default: false
163
164 • Type: Boolean
165
166
167 Run all build scripts (ie, preinstall, install, and postinstall)
168 scripts for installed packages in the foreground process, sharing stan‐
169 dard input, output, and error with the main npm process.
170
171 Note that this will generally make installs run slower, and be much
172 noisier, but can be useful for debugging.
173
174 ignore-scripts
175 • Default: false
176
177 • Type: Boolean
178
179
180 If true, npm does not run scripts specified in package.json files.
181
182 Note that commands explicitly intended to run a particular script, such
183 as npm start, npm stop, npm restart, npm test, and npm run-script will
184 still run their intended script if ignore-scripts is set, but they will
185 not run any pre- or post-scripts.
186
187 audit
188 • Default: true
189
190 • Type: Boolean
191
192
193 When "true" submit audit reports alongside the current npm command to
194 the default registry and all registries configured for scopes. See the
195 documentation for npm help audit for details on what is submitted.
196
197 bin-links
198 • Default: true
199
200 • Type: Boolean
201
202
203 Tells npm to create symlinks (or .cmd shims on Windows) for package ex‐
204 ecutables.
205
206 Set to false to have it not do this. This can be used to work around
207 the fact that some file systems don't support symlinks, even on osten‐
208 sibly Unix systems.
209
210 fund
211 • Default: true
212
213 • Type: Boolean
214
215
216 When "true" displays the message at the end of each npm install ac‐
217 knowledging the number of dependencies looking for funding. See npm
218 help fund for details.
219
220 dry-run
221 • Default: false
222
223 • Type: Boolean
224
225
226 Indicates that you don't want npm to make any changes and that it
227 should only report what it would have done. This can be passed into any
228 of the commands that modify your local installation, eg, install, up‐
229 date, dedupe, uninstall, as well as pack and publish.
230
231 Note: This is NOT honored by other network related commands, eg dist-
232 tags, owner, etc.
233
234 workspace
235 • Default:
236
237 • Type: String (can be set multiple times)
238
239
240 Enable running a command in the context of the configured workspaces of
241 the current project while filtering by running only the workspaces de‐
242 fined by this configuration option.
243
244 Valid values for the workspace config are either:
245
246 • Workspace names
247
248 • Path to a workspace directory
249
250 • Path to a parent workspace directory (will result in selecting all
251 workspaces within that folder)
252
253
254 When set for the npm init command, this may be set to the folder of a
255 workspace which does not yet exist, to create the folder and set it up
256 as a brand new workspace within the project.
257
258 This value is not exported to the environment for child processes.
259
260 workspaces
261 • Default: null
262
263 • Type: null or Boolean
264
265
266 Set to true to run the command in the context of all configured
267 workspaces.
268
269 Explicitly setting this to false will cause commands like install to
270 ignore workspaces altogether. When not set explicitly:
271
272 • Commands that operate on the node_modules tree (install, update,
273 etc.) will link workspaces into the node_modules folder. - Commands
274 that do other things (test, exec, publish, etc.) will operate on
275 the root project, unless one or more workspaces are specified in
276 the workspace config.
277
278
279 This value is not exported to the environment for child processes.
280
281 include-workspace-root
282 • Default: false
283
284 • Type: Boolean
285
286
287 Include the workspace root when workspaces are enabled for a command.
288
289 When false, specifying individual workspaces via the workspace config,
290 or all workspaces via the workspaces flag, will cause npm to operate
291 only on the specified workspaces, and not on the root project.
292
293 This value is not exported to the environment for child processes.
294
295 install-links
296 • Default: false
297
298 • Type: Boolean
299
300
301 When set file: protocol dependencies will be packed and installed as
302 regular dependencies instead of creating a symlink. This option has no
303 effect on workspaces.
304
305 See Also
306 • npm help install
307
308 • package-lock.json ⟨/configuring-npm/package-lock-json⟩
309
310
311
312 November 2023 NPM-CI(1)