subparmelon
subparmelon

Reputation: 45

Why must I delete the node_modules folder every time I pull from github

I know this may be a simple question to answer, but I am curious as to why I have to delete the node_modules folder everytime I pull from my github repo. When I try and execute "npm start" after pulling from my repo, I receive the following error, and upon deleting the node_modules folder and executing "npm install" the problem is fixed for the time being.

sh: react-scripts: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT...

I have noticed that the folder shows up as part of the changes made while pushing as well (some 2,800 files). Is this a scenario where I need to have the node_modules folder ignored (.gitignore) in order to stop this from happening? Any explanation as to why this occurs would also be cool, just as a FYI for me.

Thank you very much in advance.

Upvotes: 3

Views: 1974

Answers (2)

kuroyza
kuroyza

Reputation: 372

Create a file called .gitignore and paste the following code inside it (PS: you can use this file in all your projects, it contains almost all extensions and folders that you have to ignore when pushing your project to github):

# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
*.sass-cache
node_modules/
.tmp/
.vs

# OS or Editor folders
.DS_Store
Thumbs.db
.cache
.project
.settings
.tmproj
*.esproj
nbproject
*.sublime-project
*.sublime-workspace
*.komodoproject
.komodotools
_notes
dwsync.xml
.sass-cache
.idea

Upvotes: 4

Pedro Costa
Pedro Costa

Reputation: 194

You should add node_modules directory to .gitignore to not be pushed into repository and then delete it in there. And node_modules should only be generated in your development environment.

Upvotes: 5

Related Questions