How to update npm modules, ignoring a git repo

2019-04-03 21:09发布

I forked one of npm modules and now it is a git repo.

So my package.json:

"dependencies": {
    "some-module": "git+https://github.com/my-name/some-module.git",
}

Forked repo is synchronized by fetching upstream and merging. But when I try to update other npm modules it gives error:

npm ERR! git Appears to be a git repo or submodule.
npm ERR! git     /Users/.../node_modules/some-module
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

npm ERR! System Darwin 13.4.0
npm ERR! command "node" "/usr/local/bin/npm" "update"
npm ERR! cwd /Users/...
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! path /Users/.../node_modules/some-module
npm ERR! code EISGIT
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/.../npm-debug.log
npm ERR! not ok code 0

Is there any way to ignore git repo when updating? Or to skip this error?

标签: git npm
3条回答
我命由我不由天
2楼-- · 2019-04-03 21:18

Yes, there's a way to skip the error.

1) Open the file "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-install-checks\index.js"
2) Comment out this code at the very bottom:

if (!er && s.isDirectory()) {
  var e = new Error(folder + ': Appears to be a git repo or submodule.')
  e.path = folder
  e.code = 'EISGIT'
  return cb(e)
}

Done.

Background

From another dev long frustrated by this error; none of the suggested solutions work in my case because of constraints from various systems.

Suggestion: NPM works with symlinks, so create symlink of module from node_modules, to your library repo folder.
Problem: Then Watchman doesn't scan the JS files within.

Suggestion: Do "npm publish" and "npm install". Every. Single. Time.
Problem: Terrible for quick development tests/cycles, and spams the npm directory with hundreds of never-to-be-used versions.

Suggestion: Use Watchman Links (WML). (i.e. directory auto-copying on file-change)
Problem: Have to have a background program running all the time, for all the included repos on my machine. Also, it means I can't open the files directly in the node_modules folder to make quick changes; instead I have to go to the library's source repo every time. That's fine usually, but sometimes it's nice to make changes in the program repo, and have it reflected in the library repo, in addition to vice-versa.

My solution

So yeah, with the above change, I can use a hard-link clone of the library directory and avoid the problems above.

I use this to create the directory-level hard-link clone: http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html#hardlinkclones

The one problem with this approach is that I have to re-run the hard-link clone whenever I add or remove files in the library. But at least I don't have to do anything when changes are made within existing files. (which is by far more painful)

查看更多
成全新的幸福
3楼-- · 2019-04-03 21:28

Me too had this issue while doing npm install liberary, and i was able to solve it by removing the .git file(which is hidden inside node_moules/liberary_name) from the corresponding liberary_name mentioned in the error message . Also make sure you don't delete .git file from the root of your project because if you delete .git file from project root you might loss git related info like branch info,etc

thanks to bolav for good explanation regarding how EISGIT error is thrown

查看更多
倾城 Initia
4楼-- · 2019-04-03 21:35

npm checks all directories for the existance of a .git directory, and throws the EISGIT error if it exists, so there is no way to ignore it or skip it.

The code does however check if it's a link:

mod.parent && !mod.isLink && [checkGit, mod.realpath],

So I was able to make it work by symlinking the module into node_modules.

$ ln -s ../some-module node_modules
查看更多
登录 后发表回答