简体   繁体   English

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

[英]How to update npm modules, ignoring a git repo

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. Forked repo 通过获取上游和合并来同步。 But when I try to update other npm modules it gives error:但是当我尝试更新其他 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?有没有办法在更新时忽略 git repo? Or to skip this error?或者跳过这个错误?

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. npm 检查所有目录是否存在.git目录,如果存在则抛出EISGIT错误,因此无法忽略或跳过它。

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.所以我能够通过将模块符号链接到 node_modules 来使其工作。

$ ln -s ../some-module node_modules

I too had this issue whilst doing an npm install library and I was able to solve it by removing the .git directory (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 directory from 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目录

Thanks to bolav for good a explanation regarding how the EISGIT error is thrown.感谢bolav对如何抛出 EISGIT 错误的解释。

rm -rf node_modules/*/.git/

尝试这个

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" 1) 打开文件“C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\npm-install-checks\\index.js”
2) Comment out this code at the very bottom: 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.建议:NPM 使用符号链接,因此从 node_modules 创建模块的符号链接到您的库 repo 文件夹。
Problem: Then Watchman doesn't scan the JS files within.问题:然后 Watchman 不扫描其中的 JS 文件。

Suggestion: Do "npm publish" and "npm install".建议:做“npm publish”和“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 目录发送数百个从未使用过的版本。

Suggestion: Use Watchman Links (WML).建议:使用守望者链接 (WML)。 (ie 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;另外,这意味着我无法直接打开 node_modules 文件夹中的文件进行快速更改; 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我用它来创建目录级硬链接克隆: 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) (这是更痛苦的)

KISHOREs-MBP:dummyReactNativeProject simpro$ npm install --save react-native-gesture-handler npm ERR! 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!路径 /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/ react-native-safe-area-view npm ERR! code EISGIT npm ERR!代码 EISGIT npm ERR! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view: Appears to be a git repo or submodule. git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view:似乎是一个 git repo 或子模块。 npm ERR! npm 错误! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR! git Refusing to remove it. git 拒绝删除它。 Update manually, npm ERR!手动更新,npm ERR! git or move it out of the way first. git 或先将其移开。

npm ERR! npm 错误! A complete log of this run can be found in: npm ERR!可以在以下位置找到此运行的完整日志: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! /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 错误! path /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR!路径 /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR! code EISGIT npm ERR!代码 EISGIT npm ERR! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view: Appears to be a git repo or submodule. git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view:似乎是一个 git repo 或子模块。 npm ERR! npm 错误! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR! git /Users/simpro/Desktop/Kishore/dummyReactNativeProject/node_modules/react-native-safe-area-view npm ERR! git Refusing to remove it. git 拒绝删除它。 Update manually, npm ERR!手动更新,npm ERR! git or move it out of the way first. git 或先将其移开。

npm ERR! npm 错误! A complete log of this run can be found in: npm ERR!可以在以下位置找到此运行的完整日志:npm ERR! /Users/simpro/.npm/_logs/2019-05-10T10_33_07_251Z-debug.log /Users/simpro/.npm/_logs/2019-05-10T10_33_07_251Z-debug.log

I was also facing same issue while installing react-native-gesture-handler.我在安装 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-safe-area-view (这是给出问题的文件夹)并安装了 react-native-gesture-handler 并为我工作。

Reason:due to git原因:由于git

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM