最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - npm publish ignores files inside node_modules - Stack Overflow

programmeradmin1浏览0评论

I've created npm package. In this package I'm using some modules which I put to node_modules to be able to require them as "modules", for example I have modules node_modules/my-module.js which I require in my code as require('my-module'). Now I do "npm publish" and then in another project I do "npm i" to install my module. It is installed but there are no my modules which I put to node_modules. I tried to add the next lines to .gitignore and to .npmignore, but it did not help:

node_modules/*

!node_modules/my-module.js

what do I do wrong?

I've created npm package. In this package I'm using some modules which I put to node_modules to be able to require them as "modules", for example I have modules node_modules/my-module.js which I require in my code as require('my-module'). Now I do "npm publish" and then in another project I do "npm i" to install my module. It is installed but there are no my modules which I put to node_modules. I tried to add the next lines to .gitignore and to .npmignore, but it did not help:

node_modules/*

!node_modules/my-module.js

what do I do wrong?

Share Improve this question edited Jan 4, 2016 at 22:07 pavel06081991 asked Jan 4, 2016 at 21:48 pavel06081991pavel06081991 6271 gold badge8 silver badges14 bronze badges 2
  • Are these additional node_modules in your package.json file? – r0- Commented Jan 4, 2016 at 21:58
  • no, it is not modules from npm repository, it is my modules which I put to node_modules to be able to require them in modules style, not using relative or absolute paths – pavel06081991 Commented Jan 4, 2016 at 22:00
Add a ment  | 

3 Answers 3

Reset to default 6

I believe that all files in node_modules/ are ignored by NPM, so setting rules for node_modules in .gitignore and .npmignore will have no effect.

Additionally, everything in node_modules is ignored, except for bundled dependencies. npm automatically handles this for you, so don't bother adding node_modules to .npmignore.

Source

It's not clear to me why you want to have a package in the node_modules directory and not in the package.json file, but the short answer is that it's not possible, because that directory will be always ignored, as gauge said.

So there's two ways to go, you can put those modules in another directory and require it from his relative path or you publish those in NPM and then you require them from the package.json file.

Have you tried using something like:

!node_modules/
node_modules/*
!node_modules/my-module.js

I have that in a gitignore of mine and it has allowed publishing.

发布评论

评论列表(0)

  1. 暂无评论