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

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.

Related

node_modules folder missing after push to git remote repo

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.

Npm install doesn't download dependency assets from Git LFS on Ubuntu

Background
I have a project that's split into several smaller projects with one main project that downloads the others as dependencies of the main project.
I'm using Gitlab to host my projects in private repositories, using deploy tokens to allow npm install to download them.
The dependencies are added to the main project using the following format in package.json:
git+https://name:token#gitlab.com/group/project.git
Problem
On Windows when I do a git clone of my main project and run npm install, it does download all the assets using Git LFS, but on Ubuntu the assets aren't getting downloaded. If I check the contents of all the files tracked by Git LFS all I get is the information Git LFS placeholder. I'm using identical commands and software versions on Windows and Ubuntu, but with different results.
I've tried:
Updating to same versions of Node(10.16.0) and Npm(6.10.2) on both Windows and Ubuntu
Updating to the latest versions of Node and Npm (I had to stick to version 10.x for Node because of some dependencies not working with 12.x)
Adding a .lfsconfig file that points to the repository as described in the following issue: https://github.com/npm/npm/issues/11151
Updating Git to the latest version (2.21 on Windows and 2.22 on Ubuntu)
Current workaround
Currently I'm cloning the main project then manually cloning my dependencies into node_modules so that they're all proper git repositories so that I can then use git lfs pull in them. It works, but it's not how it should work, especially not since it's working as it should on Windows.
Question
Why is npm install handling Git LFS differently for dependencies on Ubuntu vs Windows? How do I get npm install to work properly with Git LFS on dependencies, is there a settings somewhere I need to change to e.g. enforce Git LFS downloading?
Step 1. Inside of your repository, run the following command and then commit the resulting .gitconfig and push:
$ git config -f .gitconfig lfs.url https://gitlab.com/group/project.git/info/lfs
Step 2. In the directory in which you want to npm install your project, run for example:
$ npm install -S https://gitlab.com/group/project.git

how can I avoid npm install eachtime I change branch?

I have a git repository setup in git lab. Right now each time I change branch i should do:
npm install && composer install && cp .env.example .env && artisan generate key
Cause I lose .env , node_modules and composer modules. and it takes long time reinstalling them. cause I cant run it and test the branch if I dont have node_modules and other stuff installed
I wonder if Im doing something wrong or if there is a way to make it happen.
I have done lots of search but no luck.
Thanks in advance
Are you sure the files / directories you are talking about are ignored by git (they are in your .gitignore file)? If that's not the case, here is the answer to your question:
Since they are bound to the environment you are working on, they should not be touched by git by any means. That's why you should not lose them if you checkout on another branch.
Only the composer.lock, the package-lock.json and the .env.example should be versioned. Then, when you clone the repo from GitLab, you do a npm install, a composer install, you copy the .env.example etc... in order to setup your dependencies, but the dependencies directories (eg. node_modules) should not come from your repository.
Then after a while, let's imagine you want to update your Composer dependencies. You'll do a composer update. Your composer.lock file will be updated and will be committed to your repository.
Then, if somebody on another computer pulls your changes, he will only pull the newly updated composer.lock file. He will then make a composer install, which will install (or update if he already had installed them before) the dependencies from the composer.lock into his vendor folder.
I hope it helps you, feel free to ask more details in the comments :)

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.

Resources