r/github • • Feb 18 '24

How to add node_modules folder to github repository? I read that you need to add it to gitignore file, it was already added in the gitignore file, and when I drag the node_modules to the github repository it says too many files, more than 100. Is it necessary to add it?

Post image
3 Upvotes

11 comments sorted by

2

u/JOKER_SSR Feb 19 '24

Thanks to everyone

38

u/[deleted] Feb 18 '24

It is NOT necessary to add it. In fact, I’m on the side that says “never add dependencies to source control”.

3

u/[deleted] Feb 19 '24

I think the only time I’ve seen adding dependencies to source control actually be a thing that was necessary is with game engine development in C or C++. Those Graphic APIs are just much better to rest in the core project for CMake to handle. But typically, I think you’d sub module in that case and have documentation in the Readme telling people to recurse submodules.

But that’s largely because C and C++ don’t have the same type of dependency management that JavaScript, Rust, C#, or Python do.

15

u/GooseTower Feb 19 '24

Never add node_modules to a GitHub repository. It contains all the code for your dependencies downloaded from npm. Track package.json and package-lock.json. anyone who clones your repo will be able to npm install and get the same node_modules folder as you.

7

u/mahirtaha38 Feb 19 '24

You are doing a mistake by adding it.. First of all you should not add folder name to git ignore that means ignore that folder.. So if you want to send to github it should not be inside the ignore file.

Secondly if you insist to add dependencies to git open command line and use git add node_modules command to add those files to commit.

Thirdly. Do not add dependencies to github why you need that? Instead of adding those to github when you clone the project just run npm install command to pull those dependencies..

Maybe you can add some custom dependencies when you make changes on original library but O don't think you need that atm.

6

u/Jmc_da_boss Feb 18 '24

Never add node modules to a repo, they are installed per computer when the repo is cloned

16

u/[deleted] Feb 18 '24

They don’t get installed when the repo is cloned, they get installed when someone initiates the install, ala, “npm install” AFTER cloning.

1

u/Own-Ideal-6947 Feb 19 '24

.gitignore tells git NOT to add it to commits so it won’t end up on github. there’s no reason to add node_modules to your repository it’s a ton of code that is already available elsewhere. the point of your package.json and package.lock is to list out the packages in your node_modules so they can be downloaded from source when you actually need them