【问题标题】:how to use a git repository as a dependency and import the dependency如何使用 git 存储库作为依赖项并导入依赖项
【发布时间】:2020-09-28 20:15:50
【问题描述】:

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

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

npm install from Git in a specific version,

How to use private Github repo as npm dependency

Git repository to a dependency in package.json

Import component from a different repo

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

main project => 应该使用组件

chocolate component => 那是我的组件

每次我把它放在我的 package.json(主项目 repo)中,我都会得到那个错误:

"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 密钥来访问?

【问题讨论】:

  • 那是你真正的“依赖”JSON吗?三个具有相同键和尾随逗号的条目?

标签: node.js git github npm


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您的 JSON 中似乎有错误。 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...
    }                                                                     ^
                                                                          |
                                                                          |
                                                                    remove this
    

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


    如果您希望将 Github 存储库用作 NPM 依赖项,请使用 follow the Github instructions 以及 NPM instructions。

    从 1.1.65 版开始,您可以将 GitHub 网址称为“foo”:“user/foo-project”。与 git URL 一样,可以包含 commit-ish 后缀。

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

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

    没有尾随逗号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多