【问题标题】:Fetching npm module from GitHub brings ".git" folder从 GitHub 获取 npm 模块会带来“.git”文件夹
【发布时间】:2018-05-17 23:36:19
【问题描述】:

我最近派生了一个 npm 包并根据我的需要对其进行了更新。然后,我更改了对 packages.json 的依赖项以指向我的 GitHub 存储库,它运行良好。但是,当 npm 安装模块时,它也带来了 git 文件夹(.git)。因此,当我尝试安装其他任何东西时,npm 会给我这个错误:

npm ERR! path /node_modules/react-native-static-server
npm ERR! code EISGIT
npm ERR! git /node_modules/react-native-static-server: Appears to be a git repo or submodule.
npm ERR! git /node_modules/react-native-static-server
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

我做错了什么?如何避免.git 文件夹被下载?

你可以在这里查看 repo:https://github.com/dccarmo/react-native-static-server

编辑

我的packages.json中的依赖:

"react-native-static-server": "dccarmo/react-native-static-server"

【问题讨论】:

  • "react-native-static-server": "https://github.com/dccarmo/react-native-static-server/tarball/master",最后带有 tarball 的东西不会为我下载 git 文件夹。我不知道为什么,所以我不会写它作为答案。只需将其指向 github 存储库即可下载 .git 目录。
  • @MikaS 有趣的发现!我可能会这样做作为临时修复。感谢您的帮助!
  • 有同样的问题。由于某种原因,npm 没有将.gitignore 应用为/和.npmignore。 publish thou github.com/npm/npm/issues/19073 也有类似的问题(npm 包括我的 .git 目录)
  • @Stamos 哦,好吧,很高兴知道这不仅仅是我!
  • @Stamos 请回答问题,以便我给你适当的学分。

标签: node.js git github npm


【解决方案1】:

这似乎是一个老问题,但我今天遇到了同样的事情。 我对 git 和 npm 比较陌生,但我确实找到了一些可能对某人有帮助的东西。

如果 git repo 没有有 .gitignore,则不会下载/创建 .git 文件夹。

如果 git repo 确实有 .gitignore,则下载/创建 .git 文件夹。

我有两个存储库,一个没有 .gitignore(因为当我创建它时我不知道 .gitignore 是什么或做了什么),一个有 .gitignore。我将这两个作为 npm 包包含在一个项目中,并注意到没有 .gitignore 的那个没有给我 EISGIT 错误(因为 .git 文件夹)。

所以,在我发现这个问题之后,我从那个 repo 中删除了 .gitignore,现在它也没有创建一个 .git 文件夹。

后来,我发现在项目中添加 .gitignore 和 .npmignore 现在会阻止 .git 文件夹出现。我确实没有在我的 .npmignore 中添加 .git。

【讨论】:

  • 感谢您的回答!这似乎是 npm 的一个已知问题,并且显然尚未修复。我喜欢你的解决方案,所以我会接受它,因为它有点包含我必须做的解决方案。
猜你喜欢
  • 2017-07-07
  • 1970-01-01
  • 2022-01-26
  • 2017-01-04
  • 2012-02-15
  • 1970-01-01
  • 1970-01-01
  • 2016-07-09
相关资源
最近更新 更多