npm publish isn't including all my files

别说谁变了你拦得住时间么 提交于 2020-08-21 07:52:37

问题


I npm publish'd a module. It went up fine, but then when I installed it from the registry, it turned out to be missing certain files.

When I run irish-pub in my module's project directory, sure enough, the output doesn't list those filenames.

I've checked:

  • I do not have an .npmignore file.
  • I do have a .gitignore but this only contains /node_modules/
  • the missing files are normal JS files, not things that could be ignored by default

What else could be blocking them?


回答1:


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

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




回答2:


i've had the "files" property in package.json as well (intentionaly) but used relative pathes to the list of files and directories starting with dot slash ("./"), but neither npm pack nor npm publish worked with that. removed these, all worked as expected!

so change:

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

to:

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

and run:

$ npm pack

check the gnu zipped tarfile and finaly:

$ npm publish <projectname>-<semver>.tgz



回答3:


For anyone not fixed by the above answers, npm pack and publish respect any package.json files you have in the directory tree, not just at the root.

In my case, I had a module that templated out another module with ejs, but because npm was treating the child package.json as real it was reading the files from there and not bundling everything I needed.

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




回答4:


For me, having the .gitignore file with files listed in it, inside the package folder to be published was causing the issues.

In general,

"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."



回答5:


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

You need include the path to the directory (or tarball) you're trying to publish. While the documentation on npmjs.org doesn't really indicate it, if you run npm help publish you'll get the man page, which shows that the correct usage is actually

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

I also found that I had to actually type out the path: I couldn't just use npm publish . from the directory containing my package.json file.

Hope that helps.




回答6:


Something not mentioned in other solutions is that there is an undocumented, racing precedence. For instance, I had "files": ["lib"] in my package.json. lib is my gitignore. with just that state, it works. however, there was also a lib/path/.gitignore, which trumped my files array, yielding no included lib folder.

lesson--take heed of nested .gitignore files



来源:https://stackoverflow.com/questions/27049192/npm-publish-isnt-including-all-my-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!