Given a package.json
file with several optionalDependencies
such as the following:
<code>{
"name": "myapp",
"version": "1.0.0",
"dependencies": {
"hono": "^4.5.3"
},
"optionalDependencies" {
"@cloudflare/puppeteer": "0.0.13",
"puppeteer-core": "22.6.1"
}
}
</code>
<code>{
"name": "myapp",
"version": "1.0.0",
"dependencies": {
"hono": "^4.5.3"
},
"optionalDependencies" {
"@cloudflare/puppeteer": "0.0.13",
"puppeteer-core": "22.6.1"
}
}
</code>
{
"name": "myapp",
"version": "1.0.0",
"dependencies": {
"hono": "^4.5.3"
},
"optionalDependencies" {
"@cloudflare/puppeteer": "0.0.13",
"puppeteer-core": "22.6.1"
}
}
How do I install a single optional dependency without installing the other ones?
Using npm install
without switches installs all other optional dependencies, e.g.:
<code>npm install --omit=optional && npm install [email protected]
</code>
<code>npm install --omit=optional && npm install [email protected]
</code>
npm install --omit=optional && npm install [email protected]
Using npm install
with --omit=optional
prevent the installation of the package, e.g.:
<code>npm install --omit=optional && npm install --omit=optional [email protected]
</code>
<code>npm install --omit=optional && npm install --omit=optional [email protected]
</code>
npm install --omit=optional && npm install --omit=optional [email protected]
This was tested on NPM 10.8.3. I am creating a Hono project that targets several platforms (NodeJS, AWS Lambda, Cloudflare Workers…) and each platform requires a different set of dependencies.