如何更新 npm 模块,忽略 git repo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27356915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:36:49  来源:igfitidea点击:

How to update npm modules, ignoring a git repo

gitnpm

提问by IvanZh

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

我分叉了一个 npm 模块,现在它是一个 git repo。

So my package.json:

所以我的 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:

Forked repo 通过获取上游和合并来同步。但是当我尝试更新其他 npm 模块时,它给出了错误:

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 repo?或者跳过这个错误?

采纳答案by bolav

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

npm 检查所有目录是否存在某个.git目录,EISGIT如果存在则抛出错误,因此无法忽略或跳过它。

The codedoes 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.

所以我能够通过将模块符号链接到 node_modules 来使其工作。

$ ln -s ../some-module node_modules

回答by Jose Kj

I too had this issue whilst doing an npm install library and I was able to solve it by removing the .gitdirectory (which is hidden inside node_modules/library_name) from the corresponding library_name mentioned in the error message.

我在执行 npm install library 时也遇到了这个问题,我能够通过从错误消息中提到的相应 library_name 中删除.git目录(隐藏在里面node_modules/library_name)来解决它。

Also make sure you don't delete the .git directoryfrom the root of your project because if you delete the .git directory from the project root you will lose git related info like branch info,etc

还要确保不要.git directory从项目的根目录中删除 .git 目录,因为如果从项目根目录中删除 .git 目录,您将丢失与 git 相关的信息,例如分支信息等

Thanks to bolavfor good a explanation regarding how the EISGIT error is thrown.

感谢bolav对如何抛出 EISGIT 错误的解释。

回答by Venryx

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:

1) 打开文件 "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-install-checks\index.js"
2) 注释掉最底部的这段代码:

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.

建议:NPM 使用符号链接,因此从 node_modules 创建模块的符号链接到您的库 repo 文件夹。
问题:然后 Watchman 不扫描其中的 JS 文件。

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.

建议:做“npm publish”和“npm install”。每一个。单身的。时间。
问题:对于快速开发测试/周期来说很糟糕,并且向 npm 目录发送数百个从未使用过的版本。

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.

建议:使用守望者链接 (WML)。(即文件更改时目录自动复制)
问题:必须有一个后台程序一直运行,用于我机器上包含的所有存储库。另外,这意味着我无法直接打开 node_modules 文件夹中的文件进行快速更改;相反,我每次都必须去图书馆的源代码库。这通常很好,但有时在程序存储库中进行更改并使其反映在库存储库中是很好的,反之亦然。

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

我用它来创建目录级硬链接克隆: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)

这种方法的一个问题是,每当我在库中添加或删除文件时,我都必须重新运行硬链接克隆。但至少在现有文件中进行更改时,我不必做任何事情。(这是更痛苦的)

回答by Mahendra Thotakura

rm -rf node_modules/*/.git/

Try this

尝试这个

回答by Kishore Kumar

KISHOREs-MBP:dummyReactNativeProject simpro$ npm install --save react-native-gesture-handler npm ERR! path /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-viewnpm ERR! code EISGIT npm ERR! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view: Appears to be a git repo or submodule. npm ERR! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR! git Refusing to remove it. Update manually, npm ERR! git or move it out of the way first.

KISHOREs-MBP:dummyReactNativeProject simpro$ npm install --save react-native-gesture-handler npm ERR!路径 /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/ react-native-safe-area-viewnpm ERR!代码 EISGIT npm ERR!git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view:似乎是一个 git repo 或子模块。npm 错误!git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR!git 拒绝删除它。手动更新,npm ERR!git 或先将其移开。

npm ERR! A complete log of this run can be found in: npm ERR! /Users/simpro/.npm/_logs/2019-05-10T10_29_18_510Z-debug.log KISHOREs-MBP:dummyReactNativeProject simpro$ rm -rf .git KISHOREs-MBP:dummyReactNativeProject simpro$ npm install --save react-native-gesture-handler npm ERR! path /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR! code EISGIT npm ERR! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view: Appears to be a git repo or submodule. npm ERR! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR! git Refusing to remove it. Update manually, npm ERR! git or move it out of the way first.

npm 错误!可以在以下位置找到此运行的完整日志:npm ERR!/Users/simpro/.npm/_logs/2019-05-10T10_29_18_510Z-debug.log KISHOREs-MBP:dummyReactNativeProject simpro$ rm -rf .git KISHOREs-MBP:dummyReactNativeProject simpro$ npm install--saveture reactnative npm 错误!路径 /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR!代码 EISGIT npm ERR!git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view:似乎是一个 git repo 或子模块。npm 错误!git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR!git 拒绝删除它。手动更新,npm ERR!git 或先将其移开。

npm ERR! A complete log of this run can be found in: npm ERR! /Users/simpro/.npm/_logs/2019-05-10T10_33_07_251Z-debug.log

npm 错误!可以在以下位置找到此运行的完整日志:npm ERR!/Users/simpro/.npm/_logs/2019-05-10T10_33_07_251Z-debug.log

I was also facing same issue while installing react-native-gesture-handler. then i removed react-native-safe-area-view(this was the folder giving issue) from node modules and installed react-native-gesture-handler and worked for me.

我在安装 react-native-gesture-handler 时也面临同样的问题。然后我从节点模块中删除了react-native-safe-area-view(这是给出问题的文件夹)并安装了 react-native-gesture-handler 并对我来说有效。

Reason:due to git

原因:由于git