Skip to content
Latchkey

npm pack: Usage, Options & Common Errors

Create the publishable tarball without publishing.

npm pack produces the .tgz that npm publish would upload, so you can inspect exactly which files ship before releasing.

What it does

Runs prepack/prepare, then creates a package-version.tgz in the current directory containing the files the package would publish. With --dry-run it prints the file list and tarball stats without writing the file.

Common usage

Terminal
npm pack                    # write <name>-<version>.tgz
npm pack --dry-run          # list files without writing
npm pack ./some-dir         # pack another package directory

Common CI error: wrong files in the tarball

A published package is missing dist/ or ships test files, because the files field or .npmignore is wrong. Add a pack check to CI so a bad file list fails before publish, not after.

.github/workflows/ci.yml
npm pack --dry-run 2>&1 | tee pack.txt
grep -q "dist/index.js" pack.txt || { echo "dist missing"; exit 1; }

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →