The EMPTYPACKAGE error occurs when npm tries to install or publish a package that contains no distributable files. This typically happens due to overly restrictive .gitignore rules or misconfigured package.json files field.
The EMPTYPACKAGE error indicates that npm has attempted to pack or install a package, but found zero files to distribute. This usually occurs during publishing when your package's source files are being excluded by .gitignore or .npmignore rules, or when the 'files' field in package.json is empty or misconfigured. The error can also happen if you're trying to install a package that was published in this broken state - the package tarball on the npm registry literally contains no usable files besides package.json and README.md.
Before publishing, verify exactly what files npm will include in your package. Run this command to see the contents that would be packed:
npx npm-packlistThis shows you the exact file list that will be included. If it's empty or missing critical files, proceed to the next steps.
If your source files are in .gitignore (which is normal for dist/ or build/), create a .npmignore file in your project root that explicitly allows them:
# .npmignore (create this file)
node_modules/
.git/
.github/
.env
src/
test/
*.test.js
.gitignore
.eslintrc
tsconfig.jsonLeave dist/ and lib/ included by not listing them.
Add or update the 'files' field in your package.json to explicitly specify which directories and files should be included. Use plain directory names without './' prefix:
{
"name": "my-package",
"version": "1.0.0",
"files": [
"dist",
"lib",
"src",
"README.md",
"LICENSE"
],
"main": "dist/index.js",
"types": "dist/index.d.ts"
}Note: package.json, README.md, and LICENSE are included by default.
Ensure your build process has actually created the output directory:
# Build your project first
npm run build
# Verify the dist directory exists and contains files
ls -la dist/Common issue: developers forget to run their build script before publishing. Configure prepublishOnly:
{
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build"
}
}Always test locally before pushing to npm registry:
# Create a test tarball
npm pack
# This creates my-package-1.0.0.tgz in your current directory
# Extract it to inspect contents
tar -tzf my-package-1.0.0.tgz | head -20If the output shows missing files or only contains package.json, do not run 'npm publish'. Fix your .npmignore or files field first.
If you've already published an EMPTYPACKAGE to npm registry, understand that you cannot overwrite published versions. You must publish a new version number. After fixing the issues above, increment your version (e.g., 1.0.0 to 1.0.1) and run 'npm publish' again. Consider deprecating the broken version with 'npm deprecate [email protected] "Use 1.0.1 instead"'. In monorepos, be especially careful with nested .gitignore files.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error
npm ERR! code CERT_SIGNATURE_FAILURE npm ERR! Certificate signature failure
How to fix 'npm ERR! code CERT_SIGNATURE_FAILURE' certificate signature failure