How to fix npm ERR! 413 Payload Too Large in npm
The HTTP 413 Payload Too Large error occurs when your npm package exceeds size limits. This can be caused by accidentally including build artifacts, dependencies, or large assets in your package.
Quick fix
Fixes npm ERR! 413 Payload Too Large
# Create the tarball without publishing
npm pack
# Check the size
ls -lh *.tgz
# List contents
tar -tzf your-package-1.0.0.tgz- Check package size and contents
- Create or update .npmignore
- Use files field in package.json
- Check for accidental inclusions
# Create the tarball without publishingnpm pack# Check the sizels -lh *.tgz# List contentstar -tzf your-package-1.0.0.tgznpm ERR! 413 Payload Too Large
What this error means
This error indicates that the package you're trying to publish is larger than the registry allows. npm has size limits to prevent accidental publishing of enormous packages that would impact download times and storage. The current npm registry limit is around 260MB compressed, but you should aim much smaller. Large packages usually indicate accidentally included files like node_modules, dist folders, or large assets.
Typical symptoms
- npm publish fails with 413 error
- Package file is unexpectedly large
- Publishing times out before error
- npm pack creates very large tarball
- node_modules accidentally included
- Large assets bundled in package
Common causes
- node_modules included in package
- Missing or incorrect .npmignore file
- .git directory included
- Build artifacts included (dist/, build/)
- Large binary files or assets
- Test fixtures and mock data
- Documentation with large images
How to fix "npm ERR! 413 Payload Too Large"
Preview what will be published:
# Create the tarball without publishing
npm pack
# Check the size
ls -lh *.tgz
# List contents
tar -tzf your-package-1.0.0.tgzLook for unexpected files.
Exclude unnecessary files:
# .npmignore
node_modules/
.git/
src/ # if distributing compiled only
test/
tests/
__tests__/
coverage/
.nyc_output/
*.log
.env*
.DS_Store
*.tgz
docs/
examples/Whitelist specific files instead:
{
"name": "your-package",
"files": [
"dist",
"lib",
"README.md"
]
}This is more explicit than .npmignore.
Common culprits:
# Check for large files
find . -type f -size +1M -not -path "./node_modules/*"
# Check for sensitive files
tar -tzf *.tgz | grep -E "\.env|secret|credential"For packages with large static files:
1. Host images/videos on CDN
2. Reference by URL in code
3. Use postinstall script to download if needed:
{
"scripts": {
"postinstall": "node download-assets.js"
}
}For legitimately large packages:
# Create separate packages
my-package # Core functionality
my-package-assets # Optional large assets
my-package-cli # CLI toolsUsers install only what they need.
Advanced notes
Use npm pack --dry-run to see what would be included without creating a file. The files field in package.json is generally safer than .npmignore as it's a whitelist. For packages with native binaries, consider using prebuild or node-pre-gyp to distribute prebuilt binaries separately. Large packages increase install times for all users, impacting CI/CD pipelines.
Frequently asked questions
- What does "npm ERR! 413 Payload Too Large" mean?
- This error indicates that the package you're trying to publish is larger than the registry allows. npm has size limits to prevent accidental publishing of enormous packages that would impact download times and storage. The current npm registry limit is around 260MB compressed, but you should aim much smaller.
- How do I fix "npm ERR! 413 Payload Too Large"?
- The HTTP 413 Payload Too Large error occurs when your npm package exceeds size limits. This can be caused by accidentally including build artifacts, dependencies, or large assets in your package.
- What causes "npm ERR! 413 Payload Too Large"?
- node_modules included in package Missing or incorrect .npmignore file .git directory included
- Is the "npm ERR! 413 Payload Too Large" 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
- ๐
- ๐