How to fix npm ERR! code EPACK npm ERR! Failed to create tarball in npm

npmINTERMEDIATEMEDIUMUpdated Dec 3, 2025· 140 views

The EPACK error occurs when npm cannot create a tarball (.tgz) file during npm pack or npm publish. This is typically caused by permission issues, corrupted cache, or invalid package.json configuration.

Quick fix

Fixes npm ERR! code EPACK npm ERR! Failed to create tarball

# Clear npm cache completely
npm cache clean --force

# Verify cache integrity
npm cache verify

# Try packing again
npm pack
  1. Clear npm cache and retry
  2. Check and fix directory permissions
  3. Configure npm to use user directory
  4. Validate package.json
npm — error
# Clear npm cache completely
npm cache clean --force
# Verify cache integrity
npm cache verify
# Try packing again
npm pack
npm ERR! code EPACK
npm ERR! Failed to create tarball

What this error means

This error indicates npm failed to create the compressed archive (tarball) that contains your package. The tarball is the standard format for distributing npm packages—it's what gets uploaded to the registry during publish or created locally with npm pack. The failure can occur at various stages: reading source files, compressing content, or writing the output file. The underlying cause is often permission-related or involves corrupted npm state.

Typical symptoms

  • npm pack fails without creating a .tgz file
  • npm publish fails before uploading to registry
  • Error mentions EACCES or permission denied
  • Works when run with sudo (indicates permission issue)

Common causes

  1. Insufficient write permissions in working directory
  2. Corrupted npm cache from interrupted operations
  3. Invalid or malformed package.json
  4. Disk space exhaustion
  5. Directory permissions missing execute flag

How to fix "npm ERR! code EPACK npm ERR! Failed to create tarball"

1Clear npm cache and retry

Start with the most common fix—clearing corrupted cache:

bash
# Clear npm cache completely
npm cache clean --force

# Verify cache integrity
npm cache verify

# Try packing again
npm pack
2Check and fix directory permissions

Verify you have write access to the current directory:

bash
# Check directory permissions
ls -la

# Fix ownership of npm directories (Linux/macOS)
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules

# Ensure directories are executable
chmod u+x -R ~/.npm

Important: Never use sudo npm as it creates permission conflicts.

3Configure npm to use user directory

Avoid system-wide permission issues by using a local npm directory:

bash
# Create local npm directory
mkdir -p ~/.npm-global

# Configure npm to use it
npm config set prefix '~/.npm-global'

# Add to PATH in ~/.bashrc or ~/.zshrc
export PATH=~/.npm-global/bin:$PATH
source ~/.bashrc
4Validate package.json

Ensure your package.json is valid:

bash
# Check for syntax errors
npm ls 2>&1 | head -20

# Validate JSON format
cat package.json | python -m json.tool

Required fields for publishing:

json
{
  "name": "my-package",
  "version": "1.0.0"
}
5Check disk space

Ensure sufficient disk space for tarball creation:

bash
# Linux/macOS
df -h

# Windows
wmic logicaldisk get name,size,freespace

Free up space if needed:

bash
npm cache clean --force
rm -rf node_modules
6Windows-specific fixes

On Windows, check the npm directory exists:

bash
# Check npm directory
echo %APPDATA%\npm

# Create if missing
mkdir %APPDATA%\npm

# Fix npm prefix
npm config set prefix "%APPDATA%\npm"

Advanced notes

If distributing tarballs created on Windows to Linux/macOS systems, ensure directories have execute permissions. Windows doesn't have the same permission model, so tarballs may have incorrect flags.

For private registry authentication issues, run npm install -g @scope/package first to cache credentials, then npm pack will work.

Consider using NVM (Node Version Manager) to avoid system-wide permission issues entirely.

Frequently asked questions

What does "npm ERR! code EPACK npm ERR! Failed to create tarball" mean?
This error indicates npm failed to create the compressed archive (tarball) that contains your package. The tarball is the standard format for distributing npm packages—it's what gets uploaded to the registry during publish or created locally with npm pack. The failure can occur at various stages: reading source files, compressing content, or writing the output file.
How do I fix "npm ERR! code EPACK npm ERR! Failed to create tarball"?
The EPACK error occurs when npm cannot create a tarball (.tgz) file during npm pack or npm publish. This is typically caused by permission issues, corrupted cache, or invalid package.json configuration.
What causes "npm ERR! code EPACK npm ERR! Failed to create tarball"?
Insufficient write permissions in working directory Corrupted npm cache from interrupted operations Invalid or malformed package.json
Is the "npm ERR! code EPACK npm ERR! Failed to create tarball" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading