npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

.gitignore file in package removed when installed

What I Wanted to Do

Include a .gitignore file in my package and have it present in node_modules folder when package is installed.

What Happened Instead

The .gitignore file is either removed (as in following repro) or renamed to .npmignore

Reproduction Steps

To reproduce:

mkdir test
cd test
npm init -f
touch .npmignore
touch .gitignore
Set package.json to:

  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  "keywords": [],
  "author": "",
  "license": "ISC",
  "files": [

npm pack
The .gitignore is present in the geneated tgz file
cd ..
mkdir test_install
cd test_install
npm init -f
npm install ../test/test-1.0.0.tgz
ls -a node_modules
There will not be a .gitignore in the node_modules folder


If the .gitignore is located in the package without a .npmignore in the same folder it is renamed to .npmignore after installation.

Platform Info

$ npm --versions
  test_install: '1.0.0',
  npm: '6.9.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.8.0',
  icu: '64.2',
  llhttp: '1.1.4',
  modules: '72',
  napi: '4',
  nghttp2: '1.38.0',
  node: '12.6.0',
  openssl: '1.1.1c',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.30.1',
  v8: '',
  zlib: '1.2.11'
$ node -p process.platform

I think this is probably intended behaviour to support an old use case where some people committed modules to get reproducible state (before package-lock).

I would not expect an installed package to override my git settings, so this seems reasonable to me.

You presumably have a use case where supplying a .gitignore does make sense. Perhaps you can ship a template file and rename it into place in a post-install step.

Thanks for the reply. I have proceeded as you suggest. Package the file with a different name (just gitignore in my case). Then update where it is used to rename the file to .gitignore when needed.