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 directoryCommon 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
npm publish: Usage, Options & Common ErrorsHow npm publish ships a package to the registry, scoped/access flags, and the E403/E409 auth and version-exis…
npm version: Usage, Options & Common Errorsnpm version bumps package.json, commits, and tags in one step. Usage for patch/minor/major and the "git worki…
npm --ignore-scripts - postinstall Skipped, Native Binary MissingFix breakage from npm --ignore-scripts in CI - packages that rely on postinstall (native builds, binary downl…