我最近 fork 了一个 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
文件夹?
您可以在此处查看存储库:https://github.com/dccarmo/react-native-static-server
编辑
我的packages.json
中的依赖项:
“react-native-static-server”:“dccarmo/react-native-static-server”
最佳答案
这似乎是一个老问题,但我今天遇到了同样的事情。 我对 git 和 npm 相当陌生,但我确实发现了一些可能对某人有帮助的东西。
如果 git 存储库没有有 .gitignore,则不会下载/创建 .git 文件夹。
如果 git 存储库确实有 .gitignore,则会下载/创建 .git 文件夹。
我有两个存储库,一个没有 .gitignore (因为当我创建它时,我不知道 .gitignore 是什么或做了什么),另一个带有 .gitignore。我将这两个包都作为 npm 包包含在一个项目中,并注意到没有 .gitignore 的包没有给我 EISGIT 错误(因为 .git 文件夹)。
所以,在我发现这个问题后,我从该存储库中删除了 .gitignore,现在它也不会创建 .git 文件夹。
后来,我发现向项目添加 .gitignore 和 .npmignore 现在会阻止 .git 文件夹出现。我没有在我的 .npmignore 中添加 .git。
关于node.js - 从 GitHub 获取 npm 模块会带来 ".git"文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47634465/