我正在使用离线网络,并希望使用npm安装angular-cli。我有angular-cli的zip文件,并且使用最新的node和npm版本。我正在使用以下命令:npm install ./angular-cli-master
从文件夹中安装angular-cli。但是我一直收到错误提示我没有互联网连接(这没关系)。那么我如何在离线情况下使用我从Github下载的zip安装angular-cli呢?
谢谢您的帮助。
我正在使用离线网络,并希望使用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会通过递归处理。
对于你来说,最简单的方法是在已连接的计算机上创建一个新文件夹,在其中运行npm install angular-cli
命令,然后将该文件夹压缩并传输到离线机器上。
npm root -g
可以获取全局node_modules路径。 - Tawfik Nasser2016年1月 - 查看Addy Osmani关于离线安装npm包的建议。
2017年5月 - npm 5版本以后, 你可以在npm install
命令中加入--prefer-offline
标志来实现离线安装。
yarn
默认支持此功能。
npm install -g artillery
C:\Users\{username}\npm
\node_modules\artillery
(例如artillery.7z)artillery
,artillery.cmd
(在npm文件夹的根目录)复制到服务器上artillery
,artillery.cmd
粘贴到服务器npm文件夹的根目录下(C:\Users\{serverusername}\npm
)C:\Users\{serverusername}\npm\node_modules
中npm
文件夹压缩并复制+提取到服务器上。npm pack
和npm install -g <tarfile>
时,npm仍然坚持尝试连接到注册表。express.js
和package.json
指定的所有其他依赖项,因为没有网络连接。
解决方案: 我有一个解决方案,适用于Windows(不太确定其他平台),通过这种方式安装了express
框架以及我项目所需的所有依赖项,包括cookie-parser
、jade
、morgan
等。
步骤:
Install all the package(s) on a remote machine which has an internet access.
In my case I'm using Windows on both remote as well as local machines and my requirement was of installation of express.js
on local machine . So I run below command on my remote machine to install express.js
C:\Users>npm install -g express-generator`
After installation of express.js
I created an app on my remote machine using:
C:\Users\Name\Desktop>express Project`
C:\Users\Name\Desktop\Project>npm install -g =>to install all other dependencies globally*
Now browse to location where npm
's global modules are stored, you can view the location by
C:\Users>npm config get prefix
Generally in Windows its
C:\Users\{Username}\AppData\Roaming\
Simply copy the npm
and npm-cache
folder of your remote machine.
And place both copied folders viz. npm
and npm-cache
into your local machine on same location thats
C:\Users\{Username}\AppData\Roaming\
简短回答:你不能。大多数NPM包,如@angular/cli
需要其他依赖项,这些依赖项需要在运行npm install
时安装其子依赖项。
但是,当连接到网络时可以安装cli,并且在离线时使用它。
ng new PROJ NAME
创建新项目,那么你需要连接互联网,因为该项目本身需要安装依赖项。如果只使用ng build、generate和其他功能,则应该没有问题。 - Ahmed Musallam您可以在此处找到npm install命令的文档:https://docs.npmjs.com/cli/install
我不太确定,而且很遗憾,我现在没有机会自己测试它,但我会尝试解压文件夹并删除点,像这样:
npm install /angular-cli-master
(=安装文件夹而不是zip文件)
或者只需添加zip文件扩展名,如下所示:
npm install ./angular-cli-master.tgz
(=安装zip文件而不是文件夹,文件扩展名可能为.zip或其他)
使用 node 18.x.x 测试成功。
以下是安装 http-server 包的步骤:
在线电脑:
npm install -g offline-npm
将npm模块复制到离线计算机,就这样!
node_modules
的内容应该足够了,除非你进行全局安装。另一种可能更简单的方法是在一个已连接的系统上运行npm install angular-cli
,然后将node_modules
的内容复制到离线计算机。 - DrakaSAN