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

发布于 2024-11-03 08:21:39 字数 183 浏览 3 评论 0原文

有相当多的模块在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

萌无敌 2024-11-10 08:21:39

您需要从 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")

聆听风音 2024-11-10 08:21:39

这些模块无法使用 npm 安装。

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


输入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.

引起我注意的是:npm install

在我的如果我在 mrt 模块上遇到问题,所以我这样做了(在临时目录中)

  • 克隆存储库

     git 克隆 https://github.com/oortcloud/meteorite.git
    
  • 我将其全局安装为:

    <前><代码> npm install -g ./meteorite


提示:

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

     npm install ../meteorite

并且还可以创建指向存储库的链接,以防开发中需要补丁:

     npm link ../meteorite

编辑:

现在 npm还支持 github 和 git 存储库(请参阅 https://docs.npmjs.com/cli /v6/commands/npm-install),作为简写,您可以运行:

npm i github.com:some-user/some-repo

These modules can't be installed using 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.json file it should work.


Type npm -l and a pretty help will appear like so :

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>

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

  • Clone the repo

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

       npm install -g ./meteorite
    

Tip:

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

     npm install ../meteorite

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

     npm link ../meteorite

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 :

npm i github.com:some-user/some-repo
╭ゆ眷念 2024-11-10 08:21:39

将代码从 github 下载到

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

应该执行此操作的 node_modules 目录中。

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

希望这有帮助

Download the code from github into the node_modules directory

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.

Hope this helps

狼性发作 2024-11-10 08:21:39

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

启动终端。 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

没︽人懂的悲伤 2024-11-10 08:21:39

一步一步:

  • 假设您正在开发一个 use-gulp 项目,其中
    使用(requires)node_modules,例如gulpgulp-util
  • 现在,您想要对 gulp-util lib 进行一些修改,并使用您的 use-gulp 项目在本地测试它...
  • Fork gulp-util github\bitbucket 等上的项目。
  • 切换到您的项目: cd use-gulp/node_modules
  • gulp-util 克隆为 gulp-util-devgit 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:

  • let's say you are working on a project use-gulp which
    uses(requires) node_modules like gulp and gulp-util.
  • Now you want to make some modifications to gulp-util lib and test it locally with your use-gulp project...
  • Fork gulp-util project on github\bitbucket etc.
  • Switch to your project: cd use-gulp/node_modules
  • Clone gulp-util as gulp-util-dev : git clone https://.../gulp-util.git gulp-util-dev
  • Run npm install to ensure dependencies of gulp-util-dev are available.
  • Now you have a mirror of gulp-util as gulp-util-dev. In your use-gulp project, you can now replace: require('gulp-util')...; call with : require('gulp-util-dev') to test your changes you made to gulp-util-dev
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文