如何在没有互联网连接的情况下在本地安装 NodeJS 项目? [英] How to install NodeJS project locally without internet connection?

查看:24
本文介绍了如何在没有互联网连接的情况下在本地安装 NodeJS 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我必须将其部署到无法连接到 Internet 的客户端 Windows 系统.我目前在 D:NODE 中有一个文件夹,其中包含 node.exe 和 npm.cmd 以及一个 node_modules 文件夹.为了能够从命令行运行节点,我已将 D:NODE 添加到 PATH 变量.

I have a project which I will have to deploy to client Windows systems where it will not be possible to connect to internet. I currently have a folder in D:NODE which contains node.exe and npm.cmd and a node_modules folder. To be able to run node from command line I have added D:NODE to PATH variable.

我可以在我的项目的 node_modules 中本地安装大部分模块.但是有一个 - node-windows - 需要全局安装才能工作.

I can have most of the modules installed locally inside node_modules of my project. However there's one - node-windows - which needs to be installed globally to work.

按照下面的建议,我转到 node-windows(全局安装)并将其打包(npm pack),它创建了一个 tarball.然后我用我的项目复制了那个文件,并尝试像这样在测试机器上全局安装它:npm install -g node-windows-0.1.5.tgz

Following suggestion below I went to node-windows (installed globally) and packaged it up (npm pack), which created a tarball. I have then copied that file with my project and tried to install it on the test machine globally like this: npm install -g node-windows-0.1.5.tgz

我可以看到它已安装在全局目录中.但是,当我尝试运行使用此模块的命令时,它抱怨找不到它:Error: Cannot find module 'node-windows'

I can see that it got installed in the global directory. However when I try to run the command which uses this module it complains that it cannot find it: Error: Cannot find module 'node-windows'

当我列出模块 (npm list -g) 时,它显然在列表中...

When I list the modules (npm list -g) it is clearly there in the list...

你怎么看?也谢谢你.

推荐答案

您可以在没有 Internet 连接的系统上安装软件包,方法是使用 npm 中的内置功能将它们打包.这样,节点模块就会正确安装.

You can install packages on a system without internet connection by packing them using built-in functionality in npm. This way, the node modules will be installed properly.

  1. 创建一个 package.json.
  2. 在您的 package.json 中,在 bundledDependencies (npm 上的文档).
  3. 在打包之前运行 npm install 以安装您的节点文件.
  4. 使用 npm pack 创建一个 tarball.
  5. 将 tarball 复制到没有互联网连接的机器上.
  6. 使用 npm install 安装模块.
  1. Create a package.json.
  2. In your package.json, list all the modules you need under bundledDependencies (docs on npm).
  3. Run npm install to install your node files before packing.
  4. Create a tarball with npm pack.
  5. Copy the tarball over to the machine without internet connection.
  6. Install the modules with npm install <filename>.

更新

关于您的评论,似乎没有找到您全局安装的节点模块.

Regarding your comments, it looks like your globally installed node modules isn't found.

尝试使用 npm link 命令(关于 npm 链接的文档):

Try using the npm link command (docs on npm link):

  1. cd yourAppFolder
  2. npm 链接节点窗口

这篇关于如何在没有互联网连接的情况下在本地安装 NodeJS 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆