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.
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.
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.
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.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error