Npm publish does not include all my files

I npm publish 'd module. It went fine, but then when I installed it from the registry, it turned out that some files were missing.

When I run irish-pub in my module project directory, I'm pretty sure the output does not display these file names.

I checked:

  • I do not have a .npmignore file.
  • I have a .gitignore , but it only contains /node_modules/
  • the missing files are regular JS files, not the ones that can be ignored by default

What else can block them?

+15
npm
source share
6 answers

The problem was that I had a files array in package.json. If this is present, then only the specified files are published, and everything else is effectively npmignored.

https://docs.npmjs.com/files/package.json

+19
source share

For those who do not answer the above answers, npm pack and publish the reputable package.json files that are in the directory tree, and not just in the root .

In my case, I had a module that templated another module using ejs, but since npm viewed the package.json child as real, it read files from there and did not bind everything needed.

Look for files in any .json package, not just your root.

+13
source share

I also had the "files" property in package.json (intentionally), but used a relative reference to a list of files and directories starting with a slash ("./"), but neither npm pack nor npm publish worked with this. deleted everything, everything worked as expected!

so change:

 "files": [ "./bin", "./lib" ] 

in

 "files": [ "bin", "lib" ] 

and run:

 $ npm pack 

check out gnu zipped tarfile and finaly:

 $ npm publish <projectname>-<semver>.tgz 
+11
source share

I ran into the same problem and found the answer here .

You need to specify the path to the directory (or archive) that you are trying to publish. Although the documentation on npmjs.org does not actually indicate this, if you run npm help publish , you will get a manual page that shows that the correct use is actually

npm publish <tarball> [--tag <tag>] npm publish <folder> [--tag <tag>]

I also found that I had to actually enter the path: I could not just use npm publish . from the directory containing my package.json file.

Hope this helps.

+1
source share

Other decisions do not mention that there is an undocumented race priority. For example, in my "files": ["lib"] package.json there were "files": ["lib"] . lib is my gigninor only with this state does it work. however, there was also lib/path/.gitignore that outperformed my files array, as a result of which the lib folder was not included.

lesson - pay attention to the attached .gitignore files

0
source share

For me, having a .gitignore file with the files listed in it inside the package folder that should be published caused problems.

Generally,

 "All files in the package directory are included if no local .gitignore or .npmignore file exists. If both files exist and a file is ignored by .gitignore but not by .npmignore then it will be included." 
0
source share

All Articles