5

According to the docs https://docs.npmjs.com/files/package.json#files, if you put a directory in the files section of package.json, certain files inside the specified directory will be excluded no matter what - including .DS_Store. Additionally, files in .gitignore or .npmignore should exclude files inside any directories specified in the files section of package.json.

My package.json files entry is ["src", "bin"], yet .DS_Store files in src are still going into the tarball when I run npm pack. .DS_Store is in the .gitignore as well, but npm is supposed to exclude it regardless of setup.

The README.md file is correctly being included automatically, but I can't get .DS_Store to go away without explicitly including all the file extensions I want to include in the files section of package.json.

I tried NPM 6.4.1 and 6.9.0 and got the same results, am I missing something here?

iceblueorbitz
  • 920
  • 1
  • 7
  • 17
  • Maybe only the *root* `.DS_Store` is ignored - what if you write an explicit `.npmignore`? – jonrsharpe Mar 19 '19 at 15:59
  • 1
    Had this with npm 8.0.0. Solution was to have `files` `[ "src/" ]` instead of `[ "src/**" ]` - that may be version specific. There's more discussion about the background in https://npm.community/t/ds-store-files-show-up-after-npm-publish/831 – akauppi Oct 24 '21 at 15:47

1 Answers1

0

According to npm,

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.

I suggest you create an fresh .npmignore file to override your .gitignore. A blank .npmignore will ignore .DS_Store by default as you have mentioned above. npm might have some issue parsing your .gitignore.

Noremac
  • 554
  • 2
  • 7
  • 1
    This doesn't help either unfortunately. I even tried deleting both `.npmignore` and .gitignore` and got the same results. – iceblueorbitz Mar 19 '19 at 16:11
  • 1
    I excluded `.DS_Store` in both `.gitignore` and `.npmignore` files but it didn't work. – Tien Do Jul 04 '19 at 08:07
  • `.npmignore` and `.gitignore` are both found recursively. Be sure you have only one of each file in your entire package directory. Focus on getting `.npmignore` working and use the `npm pack` command locally to troubleshoot which files are included/excluded. Publishing your package uses the same logic as `npm pack`. If you continue to have issues please post your entire package directory tree. – Noremac Jul 08 '19 at 19:05
  • I have seen this issue, you will need to ensure .gitignore is inside the folders you are including in npm bundle. I have a 'flles' section in package.json, and for each exported folder in this list, I have a .gitignore.. – Shripada May 25 '20 at 10:33