npm安装依赖报错: npm ERR! cb() never called! npm ERR! This is an error with npm itself.

一. 问题描述

用npm安装依赖时报错,如下:

npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-12-16T07_38_47_793Z-debug.log

   
   

二. 问题解决

这个问题困扰了我几天,网上答案五花八门,不过对我来说,那些方法都没有效果,记录一下我解决这个错误的步骤,如下:

  1. 删除下载好的node_modules
  2. 删除package-lock.json文件
  3. 清除npm缓存 npm cache clean --force
  4. npm install

三. 注意事项

另外,使用这个方法的前提条件就是你的npm源可连接并且有权限获取到里代码里使用的包,
并且解决了之前的报错问题,如果没有有权限,请修改包版本或者修改npm源。

这个步骤在npm install之前,清除缓存之后操作。

  1. 修改包版本
    npm 安装指定版本的包
    使用 包名@版本号 指定,
    例如,安装 Express 3.21.2,
$ npm install express@3.21.2

   
   
  1. 修改npm源为淘宝源或者可以用的其他源
//查看源
npm config get registry
//更换源
npm config set registry https://registry.npmjs.org
//淘宝源
npm config set registry https://registry.npm.taobao.org

   
   
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐