安装参考帖子
node.js安装及环境配置超详细教程【Windows系统安装包方式】
踩坑记录
1.执行npm install express -g报错
报错信息:
C:\Users\Administrator>npm install express -g // -g是全局安装的意思
npm error code ENOENT
npm error syscall open
npm error path C:\package.json
npm error errno -4058
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open 'C:\package.json'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
报错原因:
用户环境变量Path未修改
解决方案:
将默认的 C 盘下 APPData\Roaming\npm
修改成 C:\Program Files\nodejs\node_global
,点击确定
2.换源执行npm install express -g报错
报错信息:
C:\Users\Administrator>npm config set registry https://registry.npm.taobao.org
C:\Users\Administrator>npm install express -g
npm error code CERT_HAS_EXPIRED
npm error errno CERT_HAS_EXPIRED
npm error request to https://registry.npm.taobao.org/express failed, reason: certificate has expired
npm error A complete log of this run can be found in: E:\Program Files\nodejs\node_cache\_logs\2024-08-01T02_18_55_065Z-debug-0.log
报错原因:
没有使用配套的命令行工具
解决方案:
执行
npm install -g cnpm --registry=https://registry.npmmirror.com
使用定制的 cnpm (gzip 压缩支持) 命令行工具代替默认的 npm
处理结果:
未解决,原因分析错误。通过搜索发现可能是淘宝镜像源过期
解决方案:
切换镜像源,执行
npm config list //查看镜像源信息
npm cache clean --force //清除缓存
npm config set registry https://registry.npmjs.org/ //切换镜像源
npm config list //查看镜像源信息
3.执行npm install express -g报错"4048"
报错信息:
C:\Users\Lenovo>npm cache clean --force
npm warn using --force Recommended protections disabled.
npm error code EPERM
npm error syscall rmdir
npm error path D:\program\nodejs\node_cache\_cacache\tmp
npm error errno -4048
npm error [Error: EPERM: operation not permitted, rmdir 'D:\program\nodejs\node_cache\_cacache\tmp'] {
npm error errno: -4048,
npm error code: 'EPERM',
npm error syscall: 'rmdir',
npm error path: 'D:\\program\\nodejs\\node_cache\\_cacache\\tmp'
npm error }
报错原因:
权限不够,需要管理员权限
解决方案:
使用管理员权限打开命令行:
- 直接在搜索框使用管理员权限打开
- Win+R后输入cmd使用Ctrl+Shift+Enter进入CMD
- 在CMD中以管理员身份新打开命令提示符