node.js npm install 未在 GitHub 上安装最新版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23338393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm install not installing latest version on GitHub
提问by user2867106
I have a module called 'sails-mongo' and I want to update it to the newest version using the following command:
我有一个名为“sails-mongo”的模块,我想使用以下命令将其更新到最新版本:
npm update sails-mongo --save
I also tried uninstall then install again. I tried sails-mongo@latestand sails-mongo@beta.
我也试过卸载然后重新安装。我试过sails-mongo@latest和sails-mongo@beta。
Problem: The current version (master) on GitHub the package.json (https://github.com/balderdashy/sails-mongo/blob/master/package.json) file has:
问题:GitHub 上的当前版本 ( master) package.json ( https://github.com/balderdashy/sails-mongo/blob/master/package.json) 文件具有:
"dependencies": {
"async": "~0.2.9",
"lodash": "~2.4.1",
"mongodb": "1.4.2",
"waterline-errors": "~0.10.0"
},
And in the one being updated
在正在更新的那个
"dependencies": {
"async": "0.2.10",
"underscore": "1.5.2",
"underscore.string": "2.3.3",
"mongodb": "~1.3.23"
},
The only way I get the master branch is using the command npm install git+https://github.com/balderdashy/sails-mongo
我获得主分支的唯一方法是使用命令 npm install git+https://github.com/balderdashy/sails-mongo
Why doesn't sails-mongo@latestinstall the master branch?
为什么不sails-mongo@latest安装master分支?
回答by apsillers
By default, NPM dependencies are pulled from the NPM repository. Authors must manually upload new versions of their software to the NPM repository, so the "@latest" version of the code hosted on NPM is different from the latest version of the code that exists anywhere (e.g., on GitHub).
默认情况下,NPM 依赖项是从 NPM 存储库中提取的。作者必须手动将其软件的新版本上传到 NPM 存储库,因此@latestNPM 上托管的代码的“ ”版本与存在于任何地方(例如,在 GitHub 上)的最新版本的代码不同。
According to the NPM repository's info page on Sails, the latest NPM-hosted version is 0.9.16while the current GitHub versionis 0.10.0-rc3.
根据Sails 上NPM 存储库的信息页面,最新的 NPM 托管版本是 ,0.9.16而当前的 GitHub 版本是0.10.0-rc3。
If you want to have your project depend upon a particular branch or commit of a particular Git repo (instead of the version(s) hosted on the NPM repository), the NPM developers have included an explicit mechanism to allow this, detailed in "Git URLs as Dependencies" in the package.jsondocs:
如果你想让你的项目依赖于特定的 Git 存储库的特定分支或提交(而不是托管在 NPM 存储库上的版本),NPM 开发人员已经包含了一个明确的机制来允许这样做,详细信息请参见“ Git” URLs as Dependencies" 在package.json文档中:
Git URLs as Dependencies
Git urls can be of the form:
git://github.com/user/project.git#commit-ish git+ssh://user@hostname:project.git#commit-ish git+ssh://user@hostname/project.git#commit-ish git+http://user@hostname/project/blah.git#commit-ish git+https://user@hostname/project/blah.git#commit-ishThe
commit-ishcan be any tag, sha, or branch which can be supplied as an argument togit checkout. The default ismaster.
Git URL 作为依赖项
Git 网址可以采用以下形式:
git://github.com/user/project.git#commit-ish git+ssh://user@hostname:project.git#commit-ish git+ssh://user@hostname/project.git#commit-ish git+http://user@hostname/project/blah.git#commit-ish git+https://user@hostname/project/blah.git#commit-ish的
commit-ish可以是任何标签,沙,或分支可以作为参数被供给git checkout。默认值为master.
In fact, it's easier still to use a Github.com repoas a dependency:
事实上,使用 Github.com 存储库作为依赖仍然更容易:
As of version 1.1.65, you can refer to GitHub urls as just
"foo": "user/foo-project". For example:{ "name": "foo", "version": "0.0.0", "dependencies": { "express": "visionmedia/express" } }
从 1.1.65 版本开始,您可以将 GitHub 网址称为
"foo": "user/foo-project". 例如:{ "name": "foo", "version": "0.0.0", "dependencies": { "express": "visionmedia/express" } }
So, to use the Sails GitHub repo, simply use:
因此,要使用 Sails GitHub 存储库,只需使用:
"dependencies": {
"sails": "balderdashy/sails-mongo",
...
}
And to use the exact state of Sails as it exists on GitHub as of April 28, 2014, use:
要使用截至 2014 年 4 月 28 日在 GitHub 上存在的 Sails 的确切状态,请使用:
"dependencies": {
"sails": "git://github.com/balderdashy/sails-mongo#b9cdce9a48",
...
}
回答by Michael R
I had a similar issue. Via the NPM Registry I was trying to get the latest from a project I saw in in GitHub, like this:
我有一个类似的问题。通过 NPM Registry,我试图从我在 GitHub 中看到的一个项目中获取最新信息,如下所示:
//package.json
"devDependencies": {
"foo-package": "^3.3.0",
}
But the code I got back from npm install(as observed in the node_modules/folder) was not what I saw in GitHub repository's master branch. I was confused; as the two didn't match.
但是我从npm install(在node_modules/文件夹中观察到的)返回的代码并不是我在 GitHub 存储库的 master 分支中看到的。我很困惑; 因为两者不匹配。
I eventually found: https://docs.npmjs.com/cli/view, which reveals some information (versions and dates) of what the NPM Registry is aware of for a particular repository.
我最终找到了:https://docs.npmjs.com/cli/view,它揭示了 NPM Registry 所知道的特定存储库的一些信息(版本和日期)。
// Console example
npm view foo-package
After confirming that what I wanted from GitHub repository's master branch wasn't in the NPM Registry, I eventually changed my approach Git URLs as Dependencies, just as @apsillers answers.
在确认我想要从 GitHub 存储库的主分支中获得的内容不在 NPM 注册表中之后,我最终改变了我的方法 Git URLs as Dependencies,就像@apsillers 的回答一样。

