如何在离线时安装 npm 包? [英] How to install npm package while offline?
问题描述
我在离线网络上工作,想使用 npm 安装 angular-cli.我有一个 angular-cli 的 zip 文件并使用最新的 node 和 npm 版本.我正在使用命令:npm install ./angular-cli-master
从文件夹安装 angular-cli.但是我不断收到这个错误,告诉我我没有互联网连接(没关系).那么如何使用我从 Github 下载的 zip 离线安装这个 angular-cli?
感谢您的帮助.
您只需将包和所有依赖项复制到 node_modules
文件夹、本地安装项目内或全局文件夹 (npm config get prefix
以查看它所在的位置)进行全局安装.
npm install
的行为是检查依赖项,并先安装它们.当它没有找到安装它们,也没有找到包含它们的本地文件时,它会尝试下载它们.
由于所有这些步骤都失败了(您没有安装依赖项,它在预期位置不可用,并且无法下载),安装失败.
您可以在每个模块的 package.json
中找到依赖项列表,但由于它是递归的,如果您手动进行,则可能需要很长时间才能将一切设置正确,npm 可以它通过递归.
对您来说,最简单的方法是在连接的 PC 上创建一个新文件夹,然后在其中 npm install angular-cli
,将文件夹压缩并传输到离线机器上.>
I'm working on an offline network and want to install angular-cli using npm.
I have a zip file of angular-cli and using the latest node and npm version.
I'm using the command: npm install ./angular-cli-master
to install angular-cli from the folder.
But I keep getting this error telling me I don't have an internet connection (which is ok).
So how can I install this angular-cli while offline using the zip I downloaded from Github?
Thanks for your help.
You simply copy the package and all dependencies in your node_modules
folder, inside the project for local installation, or in the global folder (npm config get prefix
to see where it is located) for a global installation.
The behavior of npm install
is to check for the dependencies, and install them first. When it doesn't find them installed, nor the local file containing them, it tries to download them.
Since all of those steps fail (you don't have the dependency installed, it isn't available on the expected location, and it can't download it), the installation fails.
You can find the dependency list in the package.json
of each module, but since it is recursive, it can take a long time to have everything set right if you do it manually, npm does it by recursion.
For you, the easiest way would be to create a new folder on the connected PC, and inside it npm install angular-cli
, zip the folder and transfer it on the offline machine.
这篇关于如何在离线时安装 npm 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!