node.js安装指南 & npm配置
前言
·node 版本14.9.0
·windows10
node.js下载与安装
第一次安装不推荐使用最新版本
原因:对于依赖包在切换淘宝镜像源后仍无法安装的问题,直接切换node.js版本后问题便不复存在
下载步骤
打开官方下载地址
选择64位windows版本安装包
安装步骤
1/6
2/6
3/6
4/6
5/6
6/6
安装完成后重启电脑使环境变量配置生效
验证安装结果
查看node和npm版本,返回对应版本号表示安装成功
C:\Users\shaohuang>node -v
v14.9.0
C:\Users\shanghuang>npm -v
6.14.10
npm配置
由于npm官方镜像源访问速度慢,所以推荐使用淘宝镜像源
方案一、安装cnpm [一劳永逸]
npm install -g cnpm --registry=https://registry.npmmirror.com
方案二、指定npm源
①直接指定npm源
npm config set registry https://registry.npmmirror.com
npm config get registry
②单次使用指定npm源
npm install --registry=https://registry.npmmirror.com
至此就可以直接使用npm安装依赖项了~
问题汇总
①cannot be loaded because running scripts is disabled on this system
这个原因是由于脚本执行策略为严格模式,所以无法执行
【解决方案】要使脚本能够执行,需要修改执行策略为Unrestricted 或 Bypass
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
或者
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
②The term ‘vue’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
刚开始直接使用npm install vue进行安装,报了以上错误
【解决方案】全局安装vue-cli
npm install vue-cli -g
③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缓存所致,需要清理npm 缓存
【解决方案】
方法一:尝试清理缓存
npm cache clean -f
方法二:更新npm版本
npm install npm@latest -g --registry=https://registry.npmmirror.com