There are times when you want to download an npm package tarball (.tgz file) directly. For offline installations or when you need to inspect package contents.
npm
npm pack <package-name>
# Example: download react tarballnpm pack react# react-18.3.1.tgz is generatedThe tarball is downloaded to the current directory.
yarn
You can also use npm pack with yarn:
npm pack <package-name>
# Examplenpm pack reactNote that yarn pack serves a different purpose (packaging your own package into a tarball).
pnpm
Get the URL from the dist.tarball field:
pnpm info <package-name> dist.tarball
# Examplepnpm info react dist.tarball# https://registry.npmjs.org/react/-/react-18.3.1.tgzOnce you have the URL, download it with curl or similar:
curl -O https://registry.npmjs.org/react/-/react-18.3.1.tgzExtracting the tarball
Downloaded tarballs can be extracted with the tar command:
tar -xzf react-18.3.1.tgz# package/ directory is generatedcd package/What is a tarball?
npm packages are converted to tarballs (gzip-compressed tar archives) during npm publish and uploaded to the registry. When you run npm install, it downloads and extracts this tarball.
Downloading tarballs directly enables:
- Package distribution in offline environments
- Pre-inspection of package contents
- Backup of specific versions
hsb.horse