尝试从GitHub安装模块会导致以下错误:

package.json上的ENOENT错误。

容易复制使用express:

NPM安装https://github.com/visionmedia/express抛出错误。

NPM安装快速工程。

为什么我不能从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

当前回答

Yarn 2需要包名和Github存储库。阅读Yarn CLI的文档。

示例:yarn add <package_name>git@github.com:<owner_name>/<package_name>.git

其他回答

这些方法在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添加了准备脚本来取代预发布脚本。这修复了一个长期存在的问题,即通过Git安装的模块没有运行预发布脚本,因此没有完成模块发布到npm注册表时发生的构建步骤。参见运行预发布Git URL包#3055。

当然,模块作者需要更新他们的包。Json文件使用新的准备指令开始工作。

有时我需要从特定的分支安装或提交。 为了简单起见,我只使用https://gitpkg.vercel.app/

截至2016年9月,从普通HTTPS GitHub url安装现在可以工作:

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

你不能对所有的模块都这样做,因为你正在从一个源代码控制系统中读取,它很可能包含无效的/未编译的/有bug的代码。所以需要明确的是(尽管这应该是不言而喻的):鉴于存储库中的代码处于npm可用状态,您现在可以非常愉快地直接从GitHub安装。

2019年10月,我们正经历着“TypeScript/React/Babel峰值”,因此JavaScript编译已经变得相当普遍。如果需要考虑编译,请查看prepare。也就是说,NPM模块不需要编译,并且明智的假设编译不是默认的,特别是对于较旧的节点模块(可能也适用于非常新的、前沿的“ESNext”-y模块)。

试试这个命令:

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

这个命令对我很管用:

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

从GitHub安装,你也可以这样做

npm install visionmedia/express

Or

npm install visionmedia/express#branch

也支持直接从Gist, Bitbucket, GitLab和其他一些专门的格式安装。看看npm的安装文档。