离线时如何安装npm软件包? [英] How to install npm package while offline?
问题描述
我正在使用脱机网络,并且想使用npm安装angular-cli.
我有一个angular-cli的zip文件,并使用最新的节点和npm版本.
我正在使用命令:npm install ./angular-cli-master
从文件夹中安装angular-cli.
但是我不断收到此错误消息,告诉我我没有互联网连接(可以).
那么,如何在离线时使用从Github下载的zip来安装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?
感谢您的帮助.
推荐答案
您只需将软件包及其所有依赖项复制到node_modules
文件夹中,本地安装项目中或全局文件夹中(npm config get prefix
进行全局安装.
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.
npm install
的行为是检查依赖项,然后首先安装它们.当找不到安装的文件或包含它们的本地文件时,它会尝试下载它们.
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.
您可以在每个模块的package.json
中找到依赖项列表,但是由于它是递归的,因此如果您手动进行设置,可能需要很长时间才能正确设置所有内容,而npm会通过递归来完成.
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.
对您来说,最简单的方法是在连接的PC上创建一个新文件夹,然后在其中npm install angular-cli
压缩该文件夹并将其传输到脱机计算机上.
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屋!