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 notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm