私有 github 回购协议,因为对 npm install 的依赖是无关紧要的

Private github repo as dependency is extraneous on npm install

这是我第一次在另一个项目中使用私有仓库作为依赖项。我想我做得对,但是安装后新项目中没有依赖项,也不在 node_modules.

关注 this post 我可以看到我将其正确地包含在 package.json 中,例如:

"myPackage": "git+https://github.com/myusername/mygitrepository.git"

当我运行 npm install这个包时,我看到它没有错误,但是在列表中这个依赖项之后,它显示为extraneous(git+https://github.com/myusername/mygitrepository.git)

即使存在无关问题,也没有错误,并且依赖项不可用或未在 node_modules 中列出。

更新:repo_A package.json

{
  "name": "project-name",
  "version": "1.0.0",
  "description": "Backend utility functions",
  "scripts": {
    "test": "mocha"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/user/repo.git"
  },
  "author": "me",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/user/repo/issues"
  },
  "homepage": "https://github.com/user/repo#readme",
  "dependencies": {
    "lodash": "^4.17.4",
    "mongodb": "^2.2.25",
    "redis": "^2.7.1",
    "winston": "^2.3.1"
  }
}

更新:repo_B package.json

{
  "name": "main-project-name",
  "version": "1.0.0",
  "description": "",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/user/repo.git"
  },
  "author": "someone else",
  "homepage": "https://github.com/user/repo.git",
  "dependencies": {
    "async": "2.1.4",
    "chai": "^3.5.0",
    "langs": "1.1.0",
    "lodash": "4.13.1",
    "node-stopwatch": "0.0.1",
    "request": "2.74.0",
    "winston-loggly": "^1.3.1",
    "utils": "user/repo_A.git#master"
  },
  "scripts": {
    "test": "mocha"
  }
}

更新最新步骤 以下是我现在执行的测试每个可能解决方案的步骤,然后是输出:

rm -rf node_modules
npm cache clean
npm install

输出

├─┬ async@2.1.4
│ └── lodash@4.17.4
├─┬ chai@3.5.0
│ ├── assertion-error@1.0.2
│ ├─┬ deep-eql@0.1.3
│ │ └── type-detect@0.1.1
│ └── type-detect@1.0.0
├── util@1.0.0  extraneous (git+ssh://git@github.com/user/repo_A.git#commit-ish)
.......

如果您指定 https,那么我认为它会寻找登录用户和密码,我认为它无法自动加载。我会将其简单地列为 "user/repo" 并确保机器上有一个位于 github 中的 ssh 密钥,就像 https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#platform-linux 等帮助中描述的设置一样,并且设置了所有东西以便下拉该 repo 不需要用户交互。

编辑:经过测试,我认为问题是 package.json 中的 name 与您在主项目的依赖项中列出的方式不匹配。在我的测试中,这导致安装了模块,但我收到了无关的消息。