繁体   English   中英

如何使用 git 存储库作为依赖项并导入依赖项

[英]how to use a git repository as a dependency and import the dependency

在最后一天,我努力使用 git 存储库作为组件。 我尝试了很多方法,但当我输入npm i时,没有一个起作用

这是我尝试过的一些方法:

npm 从 Git 安装特定版本

如何使用私人 Github 回购作为 npm 依赖

Git 存储库到 package.json 中的依赖项

从不同的仓库导入组件

我在 git 中心创建了 2 个代表:

主项目=> 应该使用该组件

巧克力成分=> 那是我的成分

每次我把它放在我的 package.json(主项目回购协议)中时,我都会收到这个错误:

"dependencies": {
   "test-component": "IgorEstevao/test-component#master", # try 1
   "test-component": "git://github.com/IgorEstevao/test-component.git#0.0.1", # try 2
   "test-component": "git://github.com/IgorEstevao/test-component.git", # try 3...
}

npm ERR! premature close

我如何在主项目中使用巧克力组件?

请记住,将来展位存储库将是私有的,所以我想我需要使用 github api 密钥才能访问?

您应该将所有文件保存在项目根目录中,而不是将它们包装在my-cool-component中。

您的 JSON 似乎有错误。JSON 不允许尾随逗号。 这很烦人。

从依赖项 object 中删除最后一个逗号。

"dependencies": {
   "test-component": "IgorEstevao/test-component#master", # try 1
   "test-component": "git://github.com/IgorEstevao/test-component.git#0.0.1", # try 2
   "test-component": "git://github.com/IgorEstevao/test-component.git", # try 3...
}                                                                     ^
                                                                      |
                                                                      |
                                                                remove this

我对 NPM 不是很熟悉,但是对同一个键有三个不同的值不太可能是有效的。


如果您希望将 Github 存储库用作 NPM 依赖项, 请遵循 Github 说明以及NPM 说明

从 1.1.65 版本开始,您可以将 GitHub url 称为“foo”:“user/foo-project”。 就像 git URL 一样,可以包含一个提交后缀。

要依赖IgorEstevao/test-component存储库的主分支...

"dependencies": {
  "test-component": "IgorEstevao/test-component#master"
}

没有尾随逗号。

暂无
暂无

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

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