node.js npm 从本地位置而不是从网络安装软件包?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10298775/
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 to install packages from local position rather than from web?
提问by aaron
The problem drove me crazy, there is a package in npm database, but it has some bugs, which are already fixed in github, how could I make use of the fixed version(github version)?
这个问题把我逼疯了,npm 数据库中有一个包,但它有一些错误,这些错误已经在 github 中修复,我如何使用修复版本(github 版本)?
回答by Linus Gustav Larsson Thiel
Edit:
编辑:
You can install directly from the GitHub repository, even just using the GitHub username and the repository name:
您可以直接从 GitHub 存储库安装,甚至只需使用 GitHub 用户名和存储库名称:
npm install LearnBoost/socket.io
npm install LearnBoost/socket.io
You can also add a <commit-ish>, specifying e.g. a commit hash or a version tag, like so:
您还可以添加<commit-ish>,指定例如提交哈希或版本标签,如下所示:
npm install LearnBoost/socket.io#1.7.x
npm install LearnBoost/socket.io#1.7.x
Without a protocol, this will be interpreted as git://github.com/LearnBoost/socket.io. You can also prefix the repo with gitlab:, gist:or bitbucket:, respectively. For more information, see Using git URLs as dependencies.
如果没有协议,这将被解释为git://github.com/LearnBoost/socket.io. 您还可以分别为 repo 加上gitlab:,gist:或前缀bitbucket:。有关更多信息,请参阅使用 git URL 作为依赖项。
You can install directly from a URL, example:
您可以直接从 URL 安装,例如:
npm install https://github.com/LearnBoost/socket.io/tarball/master
You can find the URL on Github under "Downloads" on any project page. Select the "Download as tar.gz" link.
您可以在任何项目页面的“下载”下找到 Github 上的 URL。选择“下载为 tar.gz”链接。
Or you can install a tarball:
或者你可以安装一个 tarball:
npm install foo.tar.gz
See npm install(1).
请参阅npm install(1)。
Edit:
编辑:
I should mention that this works equally well in package.jsonfiles. Specify the URL instead of the version in your dependencies, like so:
我应该提到这在package.json文件中同样有效。在依赖项中指定 URL 而不是版本,如下所示:
...
"dependencies": {
"foo": "http://example.com/foo.tar.gz",
"bar": "1.2.x",
...
}
回答by Nicocube
Other temporary solution, get the github project and use npm link(http://npmjs.org/doc/link.html) to link the local folder obtained through git to your node_modulesfolder in your own project. Anyway in the end, you'll have to wait for the project maintainer to do a npm publish.
其他临时解决办法,获取github项目并使用npm link(http://npmjs.org/doc/link.html)将通过git获取的本地文件夹链接到node_modules您自己项目中的文件夹。无论如何,最终,您将不得不等待项目维护者执行npm publish.
回答by schaermu
Either add the module as a git sub-module (using git submodule) to your project or tell the module maintainer to update the version and trigger a npm publishto update the npm repository.
将模块作为 git 子模块(使用git submodule)添加到您的项目中,或者告诉模块维护者更新版本并触发npm publish更新 npm 存储库。
When using the sub-module way, be aware that you cannot update the reference using npm-commands.
使用子模块方式时,请注意不能使用npm-commands更新引用。

