How to fix npm ERR! code ENOFILES npm ERR! No files to pack in npm

npmINTERMEDIATEMEDIUMUpdated Dec 3, 2025· 127 views

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.

Quick fix

Fixes npm ERR! code ENOFILES npm ERR! No files to pack

# Run the build
npm run build

# Check output directory exists
ls -la dist/
# or
ls -la lib/
  1. Check if build output exists
  2. Create an empty .npmignore file
  3. Configure the files field properly
  4. Add prepublishOnly script
npm — error
# Run the build
npm run build
# Check output directory exists
ls -la dist/
# or
ls -la lib/
npm ERR! code ENOFILES
npm ERR! No files to pack

What this error means

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.

Typical symptoms

  • npm publish fails with "No files to pack" before uploading
  • npm pack creates an empty or near-empty tarball
  • Package installs but contains no actual code files
  • Build step runs successfully but publish fails
  • Works locally but fails in CI

Common causes

  1. .gitignore blocking the dist/build output directory
  2. Empty or misconfigured files array in package.json
  3. Build step not executed before publishing
  4. Nested .gitignore files overriding root settings
  5. Using relative paths like ./dist instead of dist

How to fix "npm ERR! code ENOFILES npm ERR! No files to pack"

1Check if build output exists

Verify your built files actually exist:

bash
# 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.

2Create an empty .npmignore file

The simplest fix—create an empty .npmignore to override .gitignore:

bash
touch .npmignore

When .npmignore exists (even empty), npm ignores .gitignore rules entirely. This allows dist/ to be included even if it's in .gitignore.

3Configure the files field properly

Use the files field to explicitly whitelist what to publish:

json
{
  "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

4Add prepublishOnly script

Ensure build runs automatically before publishing:

json
{
  "scripts": {
    "build": "tsc --outDir dist",
    "prepublishOnly": "npm run build"
  },
  "files": ["dist"]
}

npm automatically runs prepublishOnly before npm publish, so the build output will exist.

5Test with npm pack locally

Always verify before publishing:

bash
# 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.

6Check for nested .gitignore files

npm v9+ respects nested .gitignore files which can block your files:

bash
# Find all .gitignore files
find . -name ".gitignore" -type f

# Check subdirectory gitignore contents
cat dist/.gitignore

If a nested .gitignore blocks your files, remove it or use .npmignore at root level to override.

Advanced notes

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:

json
{
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "files": ["dist"],
  "scripts": {
    "build": "tsc",
    "prepublishOnly": "npm run build"
  }
}

Frequently asked questions

What does "npm ERR! code ENOFILES npm ERR! No files to pack" mean?
This error means npm's file inclusion logic resulted in zero files being available to package. gitignore to determine what to include. When you run npm pack or npm publish, npm creates a tarball containing your package.
How do I fix "npm ERR! code ENOFILES npm ERR! No files to pack"?
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.
What causes "npm ERR! code ENOFILES npm ERR! No files to pack"?
.gitignore blocking the dist/build output directory Empty or misconfigured files array in package.json Build step not executed before publishing
Is the "npm ERR! code ENOFILES npm ERR! No files to pack" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading