How to fix npm ERR! code EPACK npm ERR! Failed to create tarball in npm
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- Clear npm cache and retry
- Check and fix directory permissions
- Configure npm to use user directory
- Validate package.json
# Clear npm cache completelynpm cache clean --force# Verify cache integritynpm cache verify# Try packing againnpm packnpm ERR! code EPACKnpm 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
- Insufficient write permissions in working directory
- Corrupted npm cache from interrupted operations
- Invalid or malformed package.json
- Disk space exhaustion
- Directory permissions missing execute flag
How to fix "npm ERR! code EPACK npm ERR! Failed to create tarball"
Start with the most common fix—clearing corrupted cache:
# Clear npm cache completely
npm cache clean --force
# Verify cache integrity
npm cache verify
# Try packing again
npm packVerify you have write access to the current directory:
# 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 ~/.npmImportant: Never use sudo npm as it creates permission conflicts.
Avoid system-wide permission issues by using a local npm directory:
# 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 ~/.bashrcEnsure your package.json is valid:
# Check for syntax errors
npm ls 2>&1 | head -20
# Validate JSON format
cat package.json | python -m json.toolRequired fields for publishing:
{
"name": "my-package",
"version": "1.0.0"
}Ensure sufficient disk space for tarball creation:
# Linux/macOS
df -h
# Windows
wmic logicaldisk get name,size,freespaceFree up space if needed:
npm cache clean --force
rm -rf node_modulesOn Windows, check the npm directory exists:
# 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
- 📚npm Official Documentation
- 📖npm pack Documentation(Official Docs)
- 💬Stack Overflow: npm(Stack Overflow)
- 🐙GitHub: npm(GitHub)