如何在不使用 npm 的情况下安装 Node.js 模块?
有相当多的模块在 node 的 github 页面上列出,但并未随npm 注册表。这些模块无法使用 npm 安装。
从 Git 克隆这些 Nodejs 模块后,安装它们的正确方法是什么?
There are quite a few modules which are listed on node's github page but are not published with the npm-registry. These modules can't be installed using npm.
What is the correct way to install these nodejs modules after cloning them from Git?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要从 github 下载它们的源代码。找到主文件,然后将其包含在您的主文件中。
可以在这里找到一个例子> 如何手动安装node.js模块?
通常你需要找到源代码并浏览 package.json 文件。在那里您可以找到哪个是主文件。这样您就可以将其包含在您的应用程序中。
在您的应用程序中包含 example.js。将其复制到您的应用程序文件夹中并将其附加到主 js 文件的顶部。
var moduleName = require("path/to/example.js")
You need to download their source from the github. Find the main file and then include it in your main file.
An example of this can be found here > How to manually install a node.js module?
Usually you need to find the source and go through the package.json file. There you can find which is the main file. So that you can include that in your application.
To include example.js in your app. Copy it in your application folder and append this on the top of your main js file.
var moduleName = require("path/to/example.js")
实际上,您可以通过指定本地路径而不是名称来安装模块。只要存储库具有有效的
package.json
文件,它就应该可以工作。输入
npm -l
,就会出现一个漂亮的帮助,如下所示:CLI:
引起我注意的是:
npm install
在我的如果我在
mrt
模块上遇到问题,所以我这样做了(在临时目录中)克隆存储库
我将其全局安装为:
<前><代码> npm install -g ./meteorite
提示:
还可以以相同的方式将存储库安装到本地 npm 项目:
并且还可以创建指向存储库的链接,以防开发中需要补丁:
编辑:
现在 npm还支持 github 和 git 存储库(请参阅 https://docs.npmjs.com/cli /v6/commands/npm-install),作为简写,您可以运行:
Actually you can install a module by specifying instead of a name a local path. As long as the repository has a valid
package.json
file it should work.Type
npm -l
and a pretty help will appear like so :CLI:
What caught my eyes was:
npm install <folder>
In my case I had trouble with
mrt
module so I did this (in a temporary directory)Clone the repo
And I install it globally with:
Tip:
One can also install in the same manner the repo to a local npm project with:
And also one can create a link to the repo, in case a patch in development is needed:
Edit:
Nowadays npm supports also github and git repositories (see https://docs.npmjs.com/cli/v6/commands/npm-install), as a shorthand you can run :
将代码从 github 下载到
应该执行此操作的 node_modules 目录中。
如果模块有依赖项并且有package.json,请打开模块并输入npm install。
希望这有帮助
Download the code from github into the node_modules directory
that should do it.
if the module has dependancies and has a package.json, open the module and enter npm install.
Hope this helps
您可以将模块直接克隆到本地项目中。
启动终端。 cd 到您的项目,然后:
npm install https://github.com/repo/npm_module.git --保存
You can clone the module directly in to your local project.
Start terminal. cd in to your project and then:
npm install https://github.com/repo/npm_module.git --save
一步一步:
use-gulp
项目,其中使用(
require
s)node_modules
,例如gulp
和gulp-util
。cd use-gulp/node_modules
gulp-util
克隆为gulp-util-dev
:git clone https://.../gulp-util.git gulp-util-dev
npm install
以确保gulp-util-dev< 的依赖关系/代码>可用。
gulp-util
的镜像,作为gulp-util-dev
。在您的 use-gulp 项目中,您现在可以将require('gulp-util')...;
调用替换为:require('gulp-util -dev')
来测试您对gulp-util-dev
所做的更改Step-by-step:
use-gulp
whichuses(
require
s)node_modules
likegulp
andgulp-util
.gulp-util
lib and test it locally with youruse-gulp
project...gulp-util
project on github\bitbucket etc.cd use-gulp/node_modules
gulp-util
asgulp-util-dev
:git clone https://.../gulp-util.git gulp-util-dev
npm install
to ensure dependencies ofgulp-util-dev
are available.gulp-util
asgulp-util-dev
. In youruse-gulp
project, you can now replace:require('gulp-util')...;
call with :require('gulp-util-dev')
to test your changes you made togulp-util-dev