简体   繁体   English

如何在没有互联网连接的情况下全局安装 npm 包?

[英]How to install npm package globally without internet connection?

I need to install pm2 and pm2-windows-service package globally on a computer without an internet connection.我需要在没有互联网连接的计算机上全局安装 pm2 和 pm2-windows-service 包。 I have tried to save each package as a tarball on my own computer (with internet connection) like this:我试图将每个包保存为我自己的计算机(具有互联网连接)上的 tarball,如下所示:

npm pack pm2 
npm pack pm2-windows-startup

Then I copy both tarball files 'pm2-4.2.3.tgz' and 'pm2-windows-startup-1.0.3.tgz' to the computer without internet connection and try to install globally as follow:然后我将 tarball 文件 'pm2-4.2.3.tgz' 和 'pm2-windows-startup-1.0.3.tgz' 复制到没有互联网连接的计算机上,并尝试全局安装,如下所示:

npm i -g pm2-4.2.3.tgz
npm i -g pm2-windows-startup-1.0.3.tgz

But I always have the same error ...但我总是有同样的错误......

npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://registry.npmjs.org/@pm2%2fagent failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

Some suggestion to solve that?一些建议来解决这个问题?

According to npm documentation根据npm 文档

Global install (with -g): puts stuff in /usr/local or wherever node is installed.全局安装(使用 -g):将东西放在 /usr/local 或安装节点的任何地方。

I haven't tried it myself but what I'd try to do is to take the dependency (with all subdependencies) and put it in the directory with your node.我自己还没有尝试过,但我会尝试做的是获取依赖项(包含所有子依赖项)并将其与您的节点一起放在目录中。 Something like <PATH_TO_NODE>/node_modules .类似<PATH_TO_NODE>/node_modules

Then take the corresponding file from your local node_modules/.bin and put it in the <PATH_TO_NODE>然后从你本地的node_modules/.bin取出对应的文件,放到<PATH_TO_NODE>

If you don't know where your node is installed, you can run this command in the terminal如果你不知道你的节点安装在哪里,你可以在终端中运行这个命令

npm config get prefix

Directories will be different on UNIX systems . UNIX 系统上的目录会有所不同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM