npm Community Forum (Archive)

The npm community forum has been discontinued.

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

gitignore trumping empty npmignore in npm 5.4.2 and above (not previously)

What I Wanted to Do

My gitignored, generated files to be published when running npm publish

What Happened Instead

gitignored files were not published (except the one that main pointed to and only when using npm 5.4.2 and above)

Reproduction Steps

Original investigation of this issue


You could checkout this commit and run npm pack using npm 5.3.0 and again using npm 5.4.2

$ rm -rf cz-lerna-changelog-2.0.2.tgz package
$ npm pack
$ tar -xzf cz-lerna-changelog-2.0.2.tgz
$ ls package/lib | grep autocomplete


The docs say:

Use a .npmignore file to keep stuff out of your package. If there’s no .npmignore file, but there is a .gitignore file, then npm will ignore the stuff matched by the .gitignore file. If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it.

It looks like this was the case until somewhere between npm 5.3.0 and 4.2.0 (see screenshot below)

Platform Info

$ npm --versions
 {'cz-lerna-changelog': '2.0.2',
  npm: '5.4.2',
  ares: '1.10.1-DEV',
  cldr: '31.0.1',
  http_parser: '2.7.0',
  icu: '59.1',
  modules: '57',
  nghttp2: '1.25.0',
  node: '8.7.0',
  openssl: '1.0.2l',
  tz: '2017b',
  unicode: '9.0',
  uv: '1.15.0',
  v8: '6.1.534.42',
  zlib: '1.2.11' }
$ node -p process.platform