npm安装依赖包出错问题处理 |
您所在的位置:网站首页 › npm无法安装包 › npm安装依赖包出错问题处理 |
本文记录在使用npm安装依赖包过程中踩过的坑。一般来说,npm安装失败时需要注意下面几点: 是否能够访问安装源:检查代理和当前安装源 当前的node版本是否兼容已有模块node_modules 输入的依赖包名称是否正确解决npm ERR! code ENOENT 解决方案1:npm cache clean --force 解决方案2: npm ERR! enoent ENOENT: no such file or directory, open '/home/sida/repo/did-sidetree.js/node_modules/write-pkg/node_modules/pify/package.json.909409536'
用npm install 单独安装报错中出现的包名:例如出现上边的错,则npm install pify --registry=https://registry.npm.taobao.org npm ERR! code ECONNRESET在使用npm安装node的模块的时候,经常会出现下面的一些错误: npm ERR! network tunneling socket could not be established, cause=connect ECONNREFUSED npm ERR! code ECONNRESET npm ERR! code ETIMEOUT npm ERR! code ENOFFOUND这些错误的原因很有可能是npm使用默认的源下载安装包,而默认的安装源是国外网站,国内访问不了无法获取依赖包信息。 这时只需要更换为国内的安装源即可,可在命令行更换为国内淘宝的源: # 查看自己的安装源 npm config get registry # 更换npm源为国内淘宝镜像 npm config set registry http://registry.npm.taobao.org/ # 或者更换为国内npm官方镜像 npm config set registry http://registry.cnpmjs.org/ # 还原npm源 npm config set registry https://registry.npmjs.org/ Bash npm安装源设置上面介绍了通过命令行设置安装源地址的办法,另外还可以设置代理,以及编辑配置文件等方法。 # 命令行设置代理 npm config set proxy="http://127.0.0.1:1034" # 还可以直接使用npm设置,不需要config npm --registry https://registry.npm.taobao.org info underscore Bash另外还可以直接编辑npm安装配置文件:.npmrc,在文件末尾添加两行: registry="http://registry.npmjs.org" proxy="http://127.0.0.1:1034" Config这个文件一般在用户目录或者安装目录下。 SSL Error: CERT_UNTRUSTED这个是因为HTTPS的设置问题,可以有两种办法解决: 关掉SSL检测 使用HTTP连接的安装源命令如下: # 关闭SSL检查 npm config set strict-ssl false # 使用http安装源 npm config set registry="http://registry.npmjs.org/" Bash npm WARN unmet dependency这个错误的原因很有可能是按照依赖包的过程重网络超时等导致,可以通过清空node_module修复: # 删除node_modules目录 rm -rf node_modules/ # 情况缓存 npm cache clean # 重新安装 npm install Bash有时候,因为node版本过低也会导致该问题,可以使用下面命令更新node: npm update -g npm Bash npm ERR! code EINTEGRITYnpm install时报错:npm ERR! code EINTEGRITYnpm ERR! sha512- sha512-rkIa1OSVWTt4g9leLSK/PsqOj3HZbDKHbZj 这个问题有可能是npm版本过低导致,需要更新npm版本: # 更新npm npm install -g npm # 继续安装 npm install Bash npm ERR! code EPERM安装时出现: npm ERR! code EPERMnpm ERR! errno -4048 这个错误出现的原因很多,其中一个是因为npm安装缓存的问题,可以尝试执行下面命令清空缓存。 npm cache clean --force
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |