I created an new folder my-app by running npx create-react-app my-app in node.js command. Once the folder was created, I wanted to upload the whole thing to my repo in my github account, so I opened git bash and run the commands to push all the files and folders to the new repo I created. After updating the repo, I found that all the files have been copies expect for the node_modules folder. I actually tried to run the npx create-react-app command in git bash command window, but failed. So I have to do it in node.js first then run the commands in git bash. Additionally, the repo was created without read me file. Did I do anything wrong here? why the folder was left behind. Can anyone help.
4 Answers
This is because create-react-app is bootstraped and comes with file .gitignore
.
In which
node_modules are ignore
Why are they ignored because they are library which you can install any time by using npm install
based on package.json file.
In package.json, there is section of dependencies
, which are your node_modules. and npm install
will make them available.
"dependencies": {
"bootstrap": "^4.1.3",
"fullcalendar-reactwrapper": "^1.0.7",
"moment": "^2.22.2",
"react": "^16.5.2",
"react-date-picker": "^7.0.0",
}

- 2,932
- 3
- 19
- 33
Nothing wrong with that, create-react-app has a lot of features and one of them is the automatic creation of a .gitignore file. If you check in your working directory, at the root there is that file.
Basically what this file does is telling to git what to track and what to ignore, it is common to totally ignore the node_modules folder because when you clone your repo, you'll just need your package.json to npm install your dependencies, so there is absolutely no need to upload a lot of data (node_modules could weight a lot).

- 299
- 2
- 11
the /node_modules folder is in the .gitignore file created by create-react-app. If you remove that entry from the .gitignore folder youdshould be able to commit the node_modules.

- 423
- 2
- 9
The create-react-app comes with a file called .gitignore. This file ensures unnecessary files are not committed to git. This is the reason your node_modules aren't being committed and pushed to github.
- The main reason node_modules is included in the .gitignore is it's not necessary to push the file to the github.
- you can get the node_modules folder whenever from package.json file of your project.
- The second reason is the node_modules folder is large. Pushing it to github is a negative point.
If you want to get node_modules folder from a package.json file. You just need to run the following commands from root of the project directory when this package.json is present
if using yarn -
$ yarn install
if using npm -
$ npm install

- 47
- 7