执行npm create vite@latest时触发ERR_INVALID_URL错误,请求协助排查
解决npm create vite@latest出现ERR_INVALID_URL报错的方案
检查并修复npm镜像源
- 执行
npm config get registry查看当前镜像源地址,确认是否存在格式错误或无效链接 - 切换至官方源:
npm config set registry https://registry.npmjs.org/ - 国内用户可切换至国内镜像:
npm config set registry https://registry.npmmirror.com/
- 执行
清除npm缓存
执行npm cache clean --force清空缓存后,重新运行npm create vite@latest排查系统环境变量
- 在Windows终端执行
echo %NPM_CONFIG_REGISTRY%,检查是否存在错误的环境变量配置 - 若输出无效URL,删除对应的系统环境变量后重启终端重试
- 在Windows终端执行
检查node/npm版本兼容性
- 执行
node -v和npm -v查看版本,确保node版本为v14.18+、v16+,npm版本与node版本匹配 - 版本过旧时,建议通过nvm(Node Version Manager)升级至稳定兼容版本
- 执行
尝试替代初始化方式
- 使用yarn:
yarn create vite - 使用pnpm:
pnpm create vite - 使用npx直接调用:
npx vite@latest create
- 使用yarn:
内容的提问来源于stack exchange,提问作者shiv rathore
相关产品推荐
相关产品推荐

