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
3 Answers
Reset to default 6I 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.