尝试从 GitHub 安装模块会导致此错误:
package.json 上的 ENOENT 错误。
使用 express 轻松复制:
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
"express": "github:visionmedia/express"
添加到 package.json file
的 "dependencies"
部分,然后运行:npm install
(如下所述)
因为 https://github.com/visionmedia/express
是网页的 URL,而不是 npm 模块。使用这种风味:git+{url}.git
git+https://github.com/visionmedia/express.git
或者如果你需要 SSH,可以使用这种风格:
git+ssh://git@github.com/visionmedia/express.git
要从 GitHub 安装,您也可以这样做
npm install visionmedia/express
或者
npm install visionmedia/express#branch
还支持直接从 Gist、Bitbucket、GitLab 和许多其他专业格式安装。查看所有的 npm install
documentation。
github.com
。
如果没有安装Git,我们可以试试:
npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master
master
。这样做可能更安全。
/tarball/
截至 2016 年 9 月,从 vanilla HTTPS GitHub URL 安装现在可以工作:
npm install https://github.com/fergiemcdowall/search-index.git
您不能对所有模块执行此操作,因为您正在从源代码控制系统中读取,该系统很可能包含无效/未编译/错误代码。所以要明确一点(尽管应该不言而喻):鉴于存储库中的代码处于 npm 可用状态,您现在可以非常愉快地直接从 GitHub 安装。
2019 年 10 月,我们正处于“TypeScript/React/Babel”高峰期,因此 JavaScript 编译变得相当普遍。如果您需要考虑编译,请查看 prepare
。也就是说,NPM 模块不需要编译,并且明智的做法是假设编译不是默认的,尤其是对于较旧的节点模块(也可能对于非常新的、最前沿的“ESNext”-y 的)。
dist
文件夹,而且大多数不包含。我链接到的问题是一个 npm 错误 - 从 GitHub 安装时没有运行 prebuild
步骤。例如,尝试安装 node-influx/node-influx。
dist
文件夹的存储库,例如:npm install https://github.com/fergiemcdowall/search-index-adder
完美运行。
/lib
中有直接的 usabel 源(就像您有一个 dist 文件夹一样)。我的观点是,仅仅在 package.jons 中包含 repo 的 GitHub URL 并不能保证安装该 repo。例如,用 TypeScript 编写的模块需要将其转译的代码推送到存储库中。他们通常不这样做,而是使用预发布脚本将 .JS 代码转储到 dist 文件夹中,该文件夹会上传到 npmjs.com。
prepare
脚本,其中包括 git deps。这意味着上面关于编译和 dist 文件夹的评论已经过时了。任何将其编译正确设置为在 prepare
上运行的包都可以作为 git dep 正常工作,而无需将任何已编译的资产提交到 git 中。
现在,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 注册表时发生的构建步骤。请参阅 Run prepublish for Git URL packages #3055。
当然,模块作者需要更新他们的 package.json 文件以使用新的 prepare
指令才能开始工作。
.gitignore
个文件的问题! stackoverflow.com/questions/48287776/…
git://
协议(这是在编写此答案时)
还有 npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH}
可以使用不同的分支。
prepare
脚本。我只是想在测试存储库中安装整个存储库的一个分支,但由于构建的代码没有检入 GitHub,所以安装的只是 package.json
和自述文件。这种使用完整 URL 的 tarball
方法安装了所有源文件,这正是我所需要的。
prepare
方法!您只需要注意还包含 .gitignore
的问题:stackoverflow.com/questions/48287776/…
当前顶部的 answer by Peter Lyons 与最近的 NPM 版本无关。例如,现在可以使用在此答案中被批评的相同命令。
npm install https://github.com/visionmedia/express
如果您有持续的问题,则可能是您使用的任何软件包都有问题。
语法的一般形式是
<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。 <协议>://[<用户>[:<密码>]@]<主机名>[:<端口>][:][/]<路径>[#
你可以做:
npm install git://github.com/foo/bar.git
或在 package.json
中:
"dependencies": {
"bar": "git://github.com/foo/bar.git"
}
这对我有用,而且打字更少。
npm i github:<UserName>/<RepoName>
package.json
{
"dependencies": {
"name": "github:<UserName>/<RepoName>"
}
}
直接安装:
npm install visionmedia/express
或者,您可以将 "express": "github:visionmedia/express"
添加到 package.json
文件的 "dependencies"
部分,然后运行:
npm install
你也可以做
npm i alex-cory/fasthacks
或者
npm i github:alex-cory/fasthacks
基本上:
npm i user_or_org/repo_name
您可以通过 npm install
命令直接安装 GitHub 存储库,如下所示:
npm install https://github.com/futurechallenger/npm_git_install.git --save
注意:在将由 npm 命令安装的存储库中:
根据 Dan Dascalescu 的评论,也许你必须在你的存储库中有一个 dist 文件夹。你肯定必须在你的存储库中有一个 package.json !我忘记添加了。
dist
文件夹或任何构建代码。您只需在 package.json
中使用 prepare
脚本。
简单的:
npm install *GithubUrl*.git --save
例子:
npm install https://github.com/visionmedia/express.git --save
我尝试了 npm install git+https://github.com/visionmedia/express
,但这花费的时间太长,我不确定它是否会奏效。
对我有用的是 - yarn add git+https://github.com/visionmedia/express
。
下面的代码对我有用,可以从 github 存储库安装:
npm install git+ssh://<your_repository_ssh_clone_link>#<branch_name_if_any>
您可以获得 ssh 克隆链接,如下所示:
https://i.stack.imgur.com/EZ2fU.png
所以对于上面的截图存储库,你可能需要如下导入,
npm install git+ssh://git@github.com:Siddhu2/calculator-chatbot.git#master
其中 master 是我的分支,它是可选的,因为我只有一个分支。
如果你得到这样的东西:
npm 错误! enoent 未定义 ls-remote -h -t https://github.com/some_repo/repo.git
确保你更新到最新的 npm 并且你也有权限。
唯一对我有用的命令是 npm i MY_PACKAGE_NAME:MY_REPOSITORY#BRANCH_NAME
不需要做太多;这对我有帮助:
Yarn add <git_name>:<github_name>/<Repository_name>.git
例子:
yarn add git@github.com:myGitHub/dynamic-checkbox-input.git
如果您想添加一些特定的提交或分支名称,请添加 #
。
例子:
yarn add git@github.com:myGitHub/dynamic-checkbox-input.git#master
例子:
yarn add git@github.com:myGitHub/dynamic-checkbox-input.git#c978U57
试试这个命令:
npm install github:[Organisation]/[Repository]#[master/BranchName] -g
这个命令对我有用:
npm install github:BlessCSS/bless#3.x -g
不定期副业成功案例分享
git+https://github.com/visionmedia/express.git
来使用 https 而不是 ssh。package.json
文件,否则您将收到此错误:Error: ENOENT, open 'tmp.tgz-unpack/package.json'
。#
才能使用 shell 中的特定分支,即:npm install git+https://github.com/user/repo.git\#branch