node、npm相关记录

267 阅读1分钟

1. 清理缓存:清除 npm 缓存有时有助于解决意外问题。运行:

npm cache clean --force

2. 重新安装 node_modules*:在某些情况下,损坏的 node_modules 目录可能是问题所在。移除它并重新安装:

rm -rf node_modules

3. npm镜像:1.获取npm config get registry2.设置npm config set registry https://registry.npm.taobao.org/(淘宝镜像)

4.如果你想临时使用某个镜像源(只对当前终端窗口有效),可以这样做:

npm --registry=https://registry.npm.taobao.org install <package-name>

5.可以通过安装nrm工具来方便地管理和切换不同的npm镜像源

npm install -g nrm 安装nrm、 nrm ls 查看所有可用镜像源、 nrm use taobao使用淘宝npm镜像源、 nrm current 验证当前使用的镜像源

6.npm连接淘宝镜像报错:request to registry.npm.taobao.org/acorn failed, reason: certificate has expired

原因是:从 registry.npm.taobao.org/ 这个 URL 访问或下载名为 "acorn" 的 npm 包时,请求失败了。具体原因是服务器提供的 SSL/TLS 证书已经过期。

解决方法:临时禁用严格SSL检查:虽然不推荐在生产环境中这样做,但在开发环境下可以暂时关闭严格的SSL验证,通过运行命令 npm config set strict-ssl false,然后清除缓存: npm cache clean --force

7.使用nvm管理node版本,具体使用方法:blog.csdn.net/qq_22182989…