node_modules folder missing after push to git remote repo - node.js

Has anyone faced the problem of missing node_modules directory or any other dir after pushing to remote git repo?
I just did a git push origin master yesterday and can't find node_modules directory on my local repo since then.
I have the package.json file in my project dir, so I can just do npm install to get the modules back but wondering why it got deleted at all.
For more info, I have node_modules ignored in .gitignore file along with few others but I can see other ignored files present still in my project dir except node_modules. Anything I'm missing which can cause this? I did backup of my project dir just before pushing it to remote and can see node_modules dir present there.

Related

why can't i hide the node_module file by .gitignore after applying node_modules/ or /node_modules on nodejs

My .gitignore file is on as the same root as .git folder
i have also tried out different format like 'node_modules/' '/node_modules'
though it's hiding my .env file.
But gitignore still not hiding my node_modules folder
I have also tried by uninstalling the node_modules > updated the .gitignore file > npm install. Still it doesn't work. What should i do now?
Try using node_modules/*
This will tell git to ignore all files and folders inside the node modules folder.
Also make sure to check it by adding a dependency and using the command
git status
It will give you a list of all changed files.
It may be because your git repository is already tracking your 'node_modules' folder. Try removing the folder and commiting the change, then reinstall your node modules with npm i. The folder should then remain untracked and will appear greyed out in VS Code.

Pushing create-react-app to github node_modules folder has not been copied

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.
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",
}
Git - Ignore node_modules folder everywhere
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).
gitignore docs
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.
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

npm install creates long file names that can't be pushed to

I have some code created in the latest version of node.js. The file names in the node_modules folder can be very longer, and are sometimes longer than GitHub Desktop will accept. When trying to push some code to GitHub, I got the error:
error:
lstat("node_modules/npm/node_modules/libcipm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/node_modules/es6-promisify/node_modules/es6-promise/dist/es6-promise.auto.js"): Filename too long
fatal: Unable to process path node_modules/npm/node_modules/libcipm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/http-proxy-agent/node_modules/agent-base/node_modules/es6-promisify/node_modules/es6-promise/dist/es6-promise.auto.js
What causes this, and what I can I do to fix it?
Usually the node_modules folder is excluded from the repository by adding it to the .gitignore file.
When cloning or pulling the repository you simply run the npm install command and all the packages are automatically downloaded to the node_modules folder.

git add . command no response when adding node_modules

I have run
git init
npm install --save-dev webpack
Then, there is a package.json and a node_modules directory in the root directory.
I want to add the node_modules directory into git repo.
After I run
git add .
There is no response any more. And I found the git.exe process occupy more and more memory usage , but there is not any response after several hours.
What is wrong with it?
Is it caused by pretty much files to be added into repo by git?
How can I debug what happens in detail when that command is executed?
Everything works fine if I just git add some other files/folder which is not node_modules.
Have you git init the repo folder? If yes, then you can run git status. There you should see any new or changed folder.
If node_modules is not mentioned, I guess you have a .gitignore file in your project folder. If you want to git add the node modules folder you will need to remove node_modules/ from .gitignore.
npm install --save-dev webpack will just add one more dependency in package.json and install webpack in your node local repo. This is not a git related command.
Check also this question: Git - Ignore node_modules folder everywhere
Hopfully this will help,
I figured out myself.
This is caused by pretty much symlinks in the node_modules directory. If i evaluated the git-bash as administrator, the new installed node_module symlinks can be created as linux. And then when git add works well. Maybe, if without evaluated git-bash, git-bash can not create symlinks which cause pretty much files need to be git added, even worse maybe a circular reference between symblink and node module staff (not sure), that cause memory consumption of git increase always and no response.
Hope it can help others if met the same problem on windows.

Can't make git stop tracking package-lock.json

With npm v5 here is now package-lock.json file being created after npm install
It is recommended to commit this file, but I have issue that this file is different for some reason between my dev machine and my server. Even if I push that file to repo, after npm install on server, file changes.
So now I'm attempting to make git untrack this file. After following numerous answers from other questions, I seem to have almost managed to do so, it's not tracked on dev machine, doesn't appear in the repo itself, but after I pull code to server and make npm install, it appears in modified files.
File is in .gitignore, but server git for some reason ignores it.
git check-ignore -v -n package-lock.json
:: package-lock.json
git check-ignore -v -n --no-index package-lock.json
.gitignore:10:package-lock.json package-lock.json
Possibly relevant info:
Dev machine: Windows 10.
Server: Ubuntu 14.04.
I'm pulling code to server using tags.
You need to remove it from your repo (git rm package-lock.json) in order for git to stop tracking it.
.gitignore only works for untracked files. If you have a tracked file that is also in your .gitignore, the fact that the file is tracked overrides the fact that it is also in .gitignore.

Resources