The ENOFILES error occurs when npm cannot find any files to include in the package tarball. This happens when the files field in package.json is misconfigured or .gitignore rules exclude all publishable content.
This error means npm's file inclusion logic resulted in zero files being available to package. npm uses a combination of the "files" field in package.json, .npmignore, and .gitignore to determine what to include. When you run npm pack or npm publish, npm creates a tarball containing your package. If no files pass the inclusion filters, you get this error.
Verify your built files actually exist:
# Run the build
npm run build
# Check output directory exists
ls -la dist/
# or
ls -la lib/If dist/ is empty or missing, your build step failed or wasn't run.
The simplest fix—create an empty .npmignore to override .gitignore:
touch .npmignoreWhen .npmignore exists (even empty), npm ignores .gitignore rules entirely. This allows dist/ to be included even if it's in .gitignore.
Use the files field to explicitly whitelist what to publish:
{
"name": "my-package",
"version": "1.0.0",
"files": [
"dist",
"lib",
"README.md"
]
}Important:
- No ./ prefix (use dist, not ./dist)
- Directories include all subdirectories automatically
- package.json and README are auto-included
Ensure build runs automatically before publishing:
{
"scripts": {
"build": "tsc --outDir dist",
"prepublishOnly": "npm run build"
},
"files": ["dist"]
}npm automatically runs prepublishOnly before npm publish, so the build output will exist.
Always verify before publishing:
# Build first
npm run build
# Create tarball
npm pack
# Inspect contents
tar -tzf my-package-1.0.0.tgz
# Extract to verify
tar -xzf my-package-1.0.0.tgz
ls -la package/If the tarball only contains package.json, your files field or ignore patterns are wrong.
npm v9+ respects nested .gitignore files which can block your files:
# Find all .gitignore files
find . -name ".gitignore" -type f
# Check subdirectory gitignore contents
cat dist/.gitignoreIf a nested .gitignore blocks your files, remove it or use .npmignore at root level to override.
The relationship between .gitignore, .npmignore, and files field:
1. If "files" exists in package.json, only listed items are included (plus auto-includes)
2. If .npmignore exists, it overrides .gitignore completely
3. If neither .npmignore nor "files" exist, npm uses .gitignore rules
4. Nested .gitignore files can override root settings in npm v9+
A complete working setup for TypeScript:
{
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build"
}
}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