How to fix npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files in npm
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.
Quick fix
Fixes npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
npx npm-packlist- Check what files will be included with npm-packlist
- Create or update .npmignore to override .gitignore
- Configure the files field in package.json
- Verify your build output exists before publishing
npx npm-packlistnpm ERR! code EMPTYPACKAGEnpm ERR! Package contains no files
npx npm-packlistWhat this error means
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.
Typical symptoms
- Error message 'npm ERR! code EMPTYPACKAGE' appears when running npm publish or npm install
- Published package installs but contains no source code files
- npm pack generates a tarball with only package.json, README.md, and LICENSE
- Installation succeeds but downstream modules fail to find required files
- node_modules folder contains the package directory but it's empty of implementation files
Common causes
- All source files are excluded by .gitignore rules that npm is applying because no .npmignore file exists
- The 'files' field in package.json is empty or contains only non-existent paths
- Source code directory (like dist, lib, or src) is listed in .gitignore and not overridden
- Using relative paths with './' prefix in the files array instead of plain directory names
- Nested .gitignore files in subdirectories exclude all files in build or output directories
How to fix "npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files"
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.
Advanced notes
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 my-package@1.0.0 "Use 1.0.1 instead"'. In monorepos, be especially careful with nested .gitignore files.
Frequently asked questions
- What does "npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files" mean?
- The EMPTYPACKAGE error indicates that npm has attempted to pack or install a package, but found zero files to distribute. json is empty or misconfigured. md.
- How do I fix "npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files"?
- 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.
- What causes "npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files"?
- All source files are excluded by .gitignore rules that npm is applying because no .npmignore file exists The 'files' field in package.json is empty or contains only non-existent paths Source code directory (like dist, lib, or src) is listed in .gitignore and not overridden
- Is the "npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐Docs: package.json files field(Official Docs)
- ๐ฌSO: npm publish file issues(Stack Overflow)
- ๐GitHub: npm issues(GitHub)