npm http GET https://github.com/visionmedia/express.git
npm http 200 https://github.com/visionmedia/express.git
npm ERR! not a package /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/tmp.tgz
npm ERR! Error: ENOENT, open '/home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR! System Linux 3.8.0-23-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/visionmedia/express.git"
npm ERR! cwd /home/guym/dev_env/projects_GIT/proj/somename
npm ERR! node -v v0.10.10
npm ERR! npm -v 1.2.25
npm ERR! path /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/guym/dev_env/projects_GIT/proj/somename/npm-debug.log
npm ERR! not ok code 0
因为https://github.com/visionmedia/express
是网页的 URL,而不是 npm 模块。使用以下味道:
git+https://git@github.com/visionmedia/express.git
如果您需要 SSH,也可以使用以下方法:
git+ssh://git@github.com/visionmedia/express.git
您也可以执行npm install visionmedia/express
从 Github 安装
要么
npm install visionmedia/express#branch
还支持直接从 Gist,Bitbucket,Gitlab 和许多其他特殊格式进行安装。查看所有的npm install
文档 。
如果未安装 git,我们可以尝试
npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master
还有npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH}
以使用其他分支。
2016 年 9 月更新
现在可以从原始 https github URL 安装:
npm install https://github.com/fergiemcdowall/search-index.git
编辑 1:有几个用户评论说,您不能对所有模块都执行此操作,因为您正在从源代码控制系统读取数据,该系统很可能包含无效 / 未编译 / 错误的代码。因此要明确一点(尽管不用说): 鉴于存储库中的代码处于 npm-usable 状态 ,您现在可以很高兴地直接从 github 安装
编辑 2: (21-10-2019)我们现在生活在 “peak Typescript / React / Babel” 中,因此 JavaScript 编译已变得相当普遍。如果您需要考虑编译问题,请prepare
。就是说, 不需要编译 NPM 模块 ,并且明智的做法是假定编译不是默认的,特别是对于较旧的节点模块(也可能对于非常新的尖端 “ESNext” -y 模块)。
彼得 · 里昂斯(Peter Lyons)当前的最高答案与最新的 NPM 版本无关。例如,现在可以使用在此答案中批评的相同命令。
$ npm install https://github.com/visionmedia/express
如果您仍然遇到问题,则可能是所使用的任何软件包都存在问题。
现在, npm 的安装文档以及此处的许多其他答案已经很好地介绍了这些方法。
npm install git+ssh://git@github.com:<githubname>/<githubrepo.git[#<commit-ish>]
npm install git+ssh://git@github.com:<githubname>/<githubrepo.git>[#semver:^x.x]
npm install git+https://git@github.com/<githubname>/<githubrepo.git>
npm install git://github.com/<githubname>/<githubrepo.git>
npm install github:<githubname>/<githubrepo>[#<commit-ish>]
但是,最近发生的显着变化是 npm 添加了prepare
脚本来替换prepublish
脚本。这解决了一个长期存在的问题,即通过 git 安装的模块没有运行prepublish
脚本,因此没有完成将模块发布到 npm 注册表时发生的构建步骤。参见https://github.com/npm/npm/issues/3055 。
当然,模块作者将需要更新其 package.json 以使用新的prepare
指令来开始工作。
现在您可以执行UPDATE : npm install git://github.com/foo/bar.git
或在package.json
:
"dependencies": {
"bar": "git://github.com/foo/bar.git"
}
语法的一般形式是
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
这意味着对于您的情况
npm install git+ssh://git@github.com/visionmedia/express.git
从 npmjs 文档:
npm 安装:
从托管的 git 提供程序安装软件包,并使用 git 进行克隆。对于完整的 git 远程 URL,将仅尝试该 URL。
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish>
| #semver:] 是 git,git + ssh,git + http,git + https 或 git + file 之一。
如果提供了#,它将用于精确克隆该提交。如果 commit-ish 的格式为 #semver :,可以是任何有效的 semver 范围或确切版本,并且 npm 会在远程存储库中查找与该范围相匹配的任何标记或引用,就像对注册表依赖项一样。如果#或
semver:指定,然后使用 master。
如果存储库使用了子模块,那么这些子模块也将被克隆。
如果要安装的软件包包含 prepare 脚本,则在打包和安装软件包之前,将安装其依赖项和 devDependencies,并运行 prepare 脚本。
以下 git 环境变量被 npm 识别,并在运行 git 时添加到环境中:
- GIT_ASKPASS
- GIT_EXEC_PATH
- GIT_PROXY_COMMAND
- GIT_SSH
- GIT_SSH_COMMAND
- GIT_SSL_CAINFO GIT_SSL_NO_VERIFY
有关详细信息,请参见 git 手册页。
例子:
npm install git+ssh://git@github.com:npm/npm.git#v1.0.27 npm install git+ssh://git@github.com:npm/npm#semver:^5.0 npm install git+https://isaacs@github.com/npm/npm.git npm install git://github.com/npm/npm.git#v1.0.27 GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/npm.git npm install
直接安装:
npm install visionmedia/express
或者,您可以在package.json
文件的"dependencies"
部分中添加"express": "github:visionmedia/express"
,然后运行:
npm install