首页 文章

如何直接从GitHub安装npm包?

提问于
浏览
647

尝试从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

13 回答

  • 111

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

    要么

    npm install visionmedia/express#branch
    

    还支持直接从Gist,Bitbucket,Gitlab和许多其他专用格式进行安装 . 看看 npm install documentation为他们所有人 .

  • 45

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

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

    如果你需要SSH,还是这种味道:

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

    直接安装:

    npm install visionmedia/express
    

    或者,您可以将 "express": "github:visionmedia/express" 添加到 package.json 文件的 "dependencies" 部分,然后运行:

    npm install
    
  • 32

    这些方法现在在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>]
    

    However, something notable that has changed recently is npm adding the prepare script to replace the prepublish script. 这解决了一个长期存在的问题,即通过git安装的模块没有运行 prepublish 脚本,因此没有完成将模块发布到npm注册表时发生的构建步骤 . 见https://github.com/npm/npm/issues/3055 .

    当然,模块作者需要更新他们的package.json以使用新的 prepare 指令来开始工作 .

  • 515

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

    NOTE: 在将由npm命令安装的repo中:

    根据@Dan Dascalescu的评论,_999_也许你必须在你的回购中有一个dist文件夹 .

    • 你肯定要在你的回购中有一个 package.json !我忘了添加 .
  • 9

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

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

    语法的一般形式是

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

    这意味着你的情况

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

    来自npmjs文档:

    npm install:从托管的git提供程序安装包,用git克隆它 . 对于完整的git远程URL,只会尝试该URL . <协议>:// [<用户> [:<密码>] @] <主机名> [:<端口>] [:] [/] <路径> [#<提交肥胖型>
    | #semver:]是git,git ssh,git http,git https或git文件之一 . 如果提供了#,它将用于完全克隆该提交 . 如果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

  • 9

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

  • 866

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

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

    如果您有持续的问题,那么您使用的任何软件包都可能存在问题 .

  • -4

    你也可以这样做

    npm i alex-cory/fasthacks
    

    要么

    npm i github:alex-cory/fasthacks
    

    基本上:

    npm i user_or_org/repo_name
    
  • 12

    2016年9月更新

    从vanilla https github URL安装现在似乎工作:

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

    EDIT: 有几个用户评论说您无法为所有模块执行此操作,因为您正在从源控制系统中读取,这可能包含无效/未编译/错误代码 . 所以要清楚(虽然不用说): given that the code in the repo is in an npm-usable state ,你现在可以直接从github安装

  • 12

    试试这个命令

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

    这个命令对我有用 .

    npm install github:BlessCSS/bless#3.x -g
    
  • 3

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

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

相关问题