Recommended Free Tools
Yes—when both files are present, npm uses .npmignore and ignores .gitignore for package exclusions. If .npmignore is absent, npm uses .gitignore instead. An empty .npmignore is still an override: Git-only ignore patterns no longer keep files out of the package.
What happens when both ignore files exist?
npm does not combine the two files. It uses .npmignore when that file exists; .gitignore supplies npm’s ignore rules only when .npmignore is absent. npm documents this precedence in its npm publish file-inclusion rules and its guide to keeping files out of a package.
As an Amazon Associate I earn from qualifying purchases.
| Package setup | Effect on npm’s package exclusions |
|---|---|
.gitignore present; .npmignore absent |
npm uses the patterns in .gitignore. |
| Both files present | npm uses .npmignore; it does not use .gitignore for package exclusions. |
.npmignore present but empty |
No ignore patterns come from that file, so patterns found only in .gitignore no longer exclude files through the ignore-file fallback. |
package.json contains a files field |
The field specifies paths to include. npm’s package.json documentation says files included through this field cannot be excluded by either ignore file. |
Why an empty .npmignore can change the package
An empty .npmignore does not mean “inherit the Git ignore rules.” Its existence is enough to prevent npm from using .gitignore as the fallback. As a result, files excluded only by Git rules—such as local build output or configuration files—may become eligible for packaging.
npm applies ignore-file rules in subdirectories as well as at the package root. The patterns use .gitignore-style syntax, including glob patterns and ! negation. Some paths are treated specially: npm’s documentation says certain paths are automatically excluded, while files such as package.json, README files, and license files are always included. Check the documentation for the npm CLI version you use for the exact default list.
#1 Best Overall
How the files field affects inclusion
The files field in package.json is an inclusion allowlist: it names paths to include in the package. npm states that files included through this field cannot be excluded by .npmignore or .gitignore. Therefore, reviewing ignore files alone is not enough if the package also has a files entry. Check how the allowlist and ignore patterns interact by inspecting the package npm actually creates.
Check the archive before publishing
- Review the packaging rules. From the package directory, inspect
.npmignore,.gitignore, and thefilesfield inpackage.json. - Create a local package archive. Run
npm packin that directory. npm describes this as the local packaging step for determining which files would be uploaded. - Inspect the archive’s file list. Confirm that the files you intend to publish are present and private or otherwise unintended files are absent.
- Publish only after checking the contents. The archive preview, rather than the apparent intent of an ignore file, is the practical check on what will be packaged.
npm recommends checking package contents because a package directory can expose more files than its maintainers expect. See the npm developer guidance and npm publish documentation.
Quick Recap
Best Value
Rank #4
Rank #3
Rank #2
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →

