最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to Install All Dependency Types (Prod, Dev, Optional, Peer) of an NPM Module? - Stack Overflow

programmeradmin6浏览0评论

My goal is to download the entire dependency tree of a npm project, including production, development, optional, and peer dependencies, so I can upload them to my offline Sonatype-Nexus-Repository.

According to the npm documentation, the --include option can enable the installation of different types of dependencies, such as optional, development, peer, and production dependencies. For example:

npm install PACKAGE_NAME --no-save --include=prod --include=dev --include=optional --include=peer

However, neither a plain npm install nor the above command successfully downloads all dependencies. For instance, let’s consider the dependencies of [email protected] as defined in its package.json:

"dependencies": {
  "esbuild": "^0.21.3",
  "postcss": "^8.4.43",
  "rollup": "^4.20.0"
},
"optionalDependencies": {
  "fsevents": "~2.3.3"
},
"devDependencies": {
  "@ampproject/remapping": "^2.3.0",
  "@babel/parser": "^7.25.6",
  "@jridgewell/trace-mapping": "^0.3.25",
  "sass": "^1.77.8",
  "sass-embedded": "^1.77.8",
  ...
},
"peerDependencies": {
  "@types/node": "^18.0.0 || >=20.0.0",
  "less": "*",
  "lightningcss": "^1.21.0",
  ...
}

When I run the above command (npm install with --include flags), it only installs the dependencies and skips the devDependencies, optionalDependencies, and peerDependencies.

For example, after running:

npm install [email protected] --no-save --include=prod --include=dev --include=optional --include=peer

The output of the ls command in the node_modules folder looks like this:

@esbuild  esbuild  nanoid  picocolors  postcss  @rollup  rollup  source-map-js  @types  vite

This list includes only the main dependencies, while the other types are completely ignored.

What I’m looking for:

I need a way to install ALL dependencies of an npm module, including:

dependencies
devDependencies
optionalDependencies
peerDependencies

Is there a specific npm command or a workaround that ensures all dependency types are installed together?

(Additional Information): Why do I need all packages? My goal is to upload all dependencies of a project to an offline, private npm repository (Sonatype Nexus Repository). This repository will serve as the package source, enabling me to perform npm install and retrieve all required packages directly from the private repository.

My goal is to download the entire dependency tree of a npm project, including production, development, optional, and peer dependencies, so I can upload them to my offline Sonatype-Nexus-Repository.

According to the npm documentation, the --include option can enable the installation of different types of dependencies, such as optional, development, peer, and production dependencies. For example:

npm install PACKAGE_NAME --no-save --include=prod --include=dev --include=optional --include=peer

However, neither a plain npm install nor the above command successfully downloads all dependencies. For instance, let’s consider the dependencies of [email protected] as defined in its package.json:

"dependencies": {
  "esbuild": "^0.21.3",
  "postcss": "^8.4.43",
  "rollup": "^4.20.0"
},
"optionalDependencies": {
  "fsevents": "~2.3.3"
},
"devDependencies": {
  "@ampproject/remapping": "^2.3.0",
  "@babel/parser": "^7.25.6",
  "@jridgewell/trace-mapping": "^0.3.25",
  "sass": "^1.77.8",
  "sass-embedded": "^1.77.8",
  ...
},
"peerDependencies": {
  "@types/node": "^18.0.0 || >=20.0.0",
  "less": "*",
  "lightningcss": "^1.21.0",
  ...
}

When I run the above command (npm install with --include flags), it only installs the dependencies and skips the devDependencies, optionalDependencies, and peerDependencies.

For example, after running:

npm install [email protected] --no-save --include=prod --include=dev --include=optional --include=peer

The output of the ls command in the node_modules folder looks like this:

@esbuild  esbuild  nanoid  picocolors  postcss  @rollup  rollup  source-map-js  @types  vite

This list includes only the main dependencies, while the other types are completely ignored.

What I’m looking for:

I need a way to install ALL dependencies of an npm module, including:

dependencies
devDependencies
optionalDependencies
peerDependencies

Is there a specific npm command or a workaround that ensures all dependency types are installed together?

(Additional Information): Why do I need all packages? My goal is to upload all dependencies of a project to an offline, private npm repository (Sonatype Nexus Repository). This repository will serve as the package source, enabling me to perform npm install and retrieve all required packages directly from the private repository.

Share Improve this question edited Nov 29, 2024 at 15:27 thelearner asked Nov 29, 2024 at 15:13 thelearnerthelearner 1,1264 gold badges29 silver badges61 bronze badges 3
  • For your own repo, generally you proxy to the upstream and cache – Daniel A. White Commented Nov 29, 2024 at 15:24
  • @DanielA.White Unfortunately, this isn't possible because there is no internet connectivity in the target environment. – thelearner Commented Nov 29, 2024 at 15:26
  • To the people downvoting: how could I improve the question? – thelearner Commented Nov 30, 2024 at 12:29
Add a comment  | 

1 Answer 1

Reset to default 1 +400

npm install will not download its dev dependencies, because they are supposed to be installed only when developing the package. To install all the dependencies, you should run the command from within the package.

If you need this for an arbitrary package, you can do this: get the package's package.json, put it in an empty temp directory, and run npm install there - all the dependencies will be installed.

Here's how you can bring the package.json of a package (run it in an empty directory and it will put vite's package.json there):

curl $(npm view [email protected] | grep tarball | awk '{print$2}') | tar -x --strip-components=1 package/package.json

Now run npm install and it will install all the dependencies.

Note: specifically for this vite example, npm install fails with:

npm ERR! Unsupported URL Type "link:": link:./src/types

To make it pass, you can edit the package.json and just remove the two link dependencies from there.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论