如何直接从GitHub安装npm包?

时间:2013-07-07 05:55:04

标签: github npm npm-install node-modules

尝试从github安装模块导致:

  

package.json上的ENOENT错误。

使用快递轻松复制:

npm install https://github.com/visionmedia/express抛出错误。

npm install express有效。

为什么我不能从github安装?

这是控制台输出:

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

16 个答案:

答案 0 :(得分:980)

因为https://github.com/visionmedia/express是网页的URL而不是npm模块。使用这种味道:

git+https://git@github.com/visionmedia/express.git
如果您需要SSH,请使用

或这种风格:

git+ssh://git@github.com/visionmedia/express.git

答案 1 :(得分:583)

您也可以从Github安装npm install visionmedia/express

npm install visionmedia/express#branch

还支持直接从Gist,Bitbucket,Gitlab和许多其他专用格式进行安装。全部查看npm install documentation

答案 2 :(得分:128)

如果没有安装git,我们可以尝试

npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master

答案 3 :(得分:47)

还有npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH}使用不同的分支。

答案 4 :(得分:41)

2016年9月更新

现在可以使用vanilla https github URL进行安装:

npm install https://github.com/fergiemcdowall/search-index.git

编辑:有几位用户评论说您无法为所有模块执行此操作,因为您正在从源控制系统中读取,这可能包含无效/未编译/错误码。所以要清楚(尽管不言而喻):鉴于repo中的代码处于npm可用状态,您现在可以直接从github安装

答案 5 :(得分:34)

Peter Lyons目前的最佳答案与最近的NPM版本无关。例如,使用在这个答案中被批评的相同命令现在很好。

$ npm install https://github.com/visionmedia/express

如果您遇到问题,那么无论您使用什么包装都可能存在问题。

答案 6 :(得分:22)

这些方法现在在npm's install documentation以及其他许多答案中都有很好的涵盖。

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指令开始工作。

答案 7 :(得分:16)

更新现在您可以:npm install git://github.com/foo/bar.git
或在package.json

"dependencies": {
  "bar": "git://github.com/foo/bar.git"
}

答案 8 :(得分:16)

语法的一般形式是

<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]

这意味着你的情况将是

npm install git+ssh://git@github.com/visionmedia/express.git

来自npmjs docs:

  

npm install:

     

从托管的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,并进行准备   在打包和安装软件包之前,将运行脚本。

     

以下git环境变量由npm和will识别   运行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

答案 9 :(得分:14)

直接安装:

reinterpret_cast

或者,您可以将template <typename T> operator T&()添加到npm install visionmedia/express 文件的"express": "github:visionmedia/express"部分,然后运行:

"dependencies"

答案 10 :(得分:9)

您也可以

npm i alex-cory/fasthacks

npm i github:alex-cory/fasthacks

基本上:

npm i user_or_org/repo_name

答案 11 :(得分:5)

您可以通过npm install命令直接安装github repo,如下所示: npm install https://github.com/futurechallenger/npm_git_install.git --save

注意:在将由npm命令安装的仓库中:

  1. 根据@Dan Dascalescu的评论,也许你必须在你的回购中有一个 dist 文件夹。
  2. 您必须在回购中拥有 package.json !我忘了添加。

答案 12 :(得分:3)

简单:

npm install *GithubUrl*.git --save

示例:

npm install https://github.com/visionmedia/express.git --save

答案 13 :(得分:0)

如果你得到这样的东西:

<块引用>

npm 错误! enoent 未定义 ls-remote -h -t https://github.com/some_repo/repo.git

确保您更新到最新的 npm 并且您也有权限。

答案 14 :(得分:-1)

我尝试了npm install git+https://github.com/visionmedia/express,但是花了太长时间,我不确定是否可以。

对我有用的是-yarn add git+https://github.com/visionmedia/express

答案 15 :(得分:-3)

尝试此命令

 npm install github:[Organisation]/[Repository]#[master/BranchName] -g

这个命令对我有用。

 npm install github:BlessCSS/bless#3.x -g
相关问题