如何在不使用 npm 的情况下安装 node.js 模块?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5786433/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:05:51  来源:igfitidea点击:

How to install a node.js module without using npm?

node.jspackagesnpm

提问by vivekian2

There are quite a few modules which are listed on node's github pagebut are not published with the npm-registry. These modules can't be installed using npm.

有很多模块列在 node 的 github 页面上,但没有与 npm-registry 一起发布。这些模块不能使用 npm 安装。

What is the correct way to install these nodejs modules after cloning them from Git?

从 Git 克隆后安装这些 nodejs 模块的正确方法是什么?

采纳答案by neebz

You need to download their source from the github. Find the main file and then include it in your main file.

您需要从 github 下载他们的源代码。找到主文件,然后将其包含在主文件中。

An example of this can be found here > How to manually install a node.js module?

可以在此处找到一个示例 >如何手动安装 node.js 模块?

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.

通常你需要找到源并浏览 package.json 文件。在那里你可以找到哪个是主文件。这样您就可以将其包含在您的应用程序中。

To include example.js in your app. Copy it in your application folder and append this on the top of your main js file.

在您的应用程序中包含 example.js。将其复制到您的应用程序文件夹中,并将其附加到您的主 js 文件的顶部。

var moduleName = require("path/to/example.js")

var moduleName = require("path/to/example.js")

回答by Tiberiu C.

These modules can't be installed using npm.

这些模块不能使用 npm 安装。

Actually you can install a module by specifying instead of a name a local path. As long as the repository has a valid package.jsonfile it should work.

实际上,您可以通过指定本地路径而不是名称来安装模块。只要存储库有一个有效的package.json文件,它就应该可以工作。



Type npm -land a pretty help will appear like so :

键入npm -l和一个漂亮的帮助将如下所示:

CLI:

命令行界面:

...
install     npm install <tarball file>
                npm install <tarball url>
                npm install <folder>
                npm install <pkg>
                npm install <pkg>@<tag>
                npm install <pkg>@<version>
                npm install <pkg>@<version range>

                Can specify one or more: npm install ./foo.tgz bar@stable /some/folder
                If no argument is supplied and ./npm-shrinkwrap.json is 
                present, installs dependencies specified in the shrinkwrap.
                Otherwise, installs dependencies from ./package.json.

What caught my eyes was: npm install <folder>

吸引我眼球的是: npm install <folder>

In my case I had trouble with mrtmodule so I did this (in a temporary directory)

就我而言,我遇到了mrt模块问题,所以我这样做了(在临时目录中)

  • Clone the repo

     git clone https://github.com/oortcloud/meteorite.git
    
  • And I install it globally with:

     npm install -g ./meteorite
    
  • 克隆回购

     git clone https://github.com/oortcloud/meteorite.git
    
  • 我在全球范围内安装它:

     npm install -g ./meteorite
    


Tip:

提示:

One can also install in the same manner the repo to a local npm project with:

还可以以相同的方式将 repo 安装到本地 npm 项目:

     npm install ../meteorite

And also one can create a link to the repo, in case a patch in development is needed:

还可以创建一个到 repo 的链接,以防需要开发补丁:

     npm link ../meteorite

回答by iancrowther

Download the code from github into the node_modules directory

从github下载代码到node_modules目录

var moduleName = require("<name of directory>")

that should do it.

应该这样做。

if the module has dependancies and has a package.json, open the module and enter npm install.

如果模块有依赖并且有 package.json,打开模块并输入 npm install。

Hope this helps

希望这可以帮助

回答by Molnfront

You can clone the module directly in to your local project.

您可以将模块直接克隆到本地项目中。

Start terminal. cd in to your project and then:

启动终端。cd 进入您的项目,然后:

npm install https://github.com/repo/npm_module.git--save

npm 安装https://github.com/repo/npm_module.git--save

回答by Vikram

Step-by-step:

一步步:

  • let's say you are working on a project use-gulpwhich uses(requires) node_moduleslike gulpand gulp-util.
  • Now you want to make some modifications to gulp-utillib and test it locally with your use-gulpproject...
  • Fork gulp-utilproject on github\bitbucket etc.
  • Switch to your project: cd use-gulp/node_modules
  • Clone gulp-utilas gulp-util-dev: git clone https://.../gulp-util.git gulp-util-dev
  • Run npm installto ensure dependencies of gulp-util-devare available.
  • Now you have a mirror of gulp-utilas gulp-util-dev. In your use-gulpproject, you can now replace: require('gulp-util')...;call with : require('gulp-util-dev')to test your changes you made to gulp-util-dev
  • 让我们说你是工作的一个项目use-gulp,它使用(requireS)node_modules喜欢gulpgulp-util
  • 现在您想对gulp-utillib进行一些修改并使用您的use-gulp项目在本地对其进行测试...
  • gulp-util在 github\bitbucket 等上fork项目。
  • 切换到您的项目: cd use-gulp/node_modules
  • 克隆gulp-utilgulp-util-devgit clone https://.../gulp-util.git gulp-util-dev
  • 运行npm install以确保 的依赖项gulp-util-dev可用。
  • 现在你有一个gulp-utilas的镜像gulp-util-dev。在您的use-gulp项目中,您现在可以将: require('gulp-util')...;call替换为 :require('gulp-util-dev')来测试您所做的更改gulp-util-dev