报错方式
success Installed "create-vite@3.0.0" with binaries:
- create-vite
- cva
文件名、目录名或卷标语法不正确。
error Command failed.
Exit code: 1
Command: D:\nodejs\node_global\bin\create-vite
Arguments: my-vue-app --template vue
错误原因
yarn的安装包默认是在c盘的而我yarn安装在D盘的所以就会报这样的错误!
使用命令查看位置
yarn global dir
可查看到
C:\Users\JAVA\AppData\Local\Yarn\Data\global
解决办法
1.将yarn的全局路径改到D盘就行了,在D盘创建yarn文件夹在文件下创建一个golbal和cache文件夹
2.执行下列命令
yarn config set global-folder "D:\yarn\global"
yarn config set cache-folder "D:\yarn\cache"
复盘收集到的其他可能解决方法,本来以为是路径问题,或者版本问题,没想到都不是,但是都记录一下吧,方便其他人查找解决。
一.空格问题(本来是以为是因为这个Program Files的目录有问题,后面发现不少)
yarn create v1.22.18
[1/4] Resolving packages...
warning create-vite-app@1.21.0: create-vite-app has been deprecated. run `npm init @vitejs/app` or `yarn create @vitejs/app` instead.
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "create-vite-app@1.21.0" with binaries:
- create-vite-app
- cva
[##############] 14/14'D:\Program' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
error Command failed.
Exit code: 1
Command: D:\Program Files\nodejs\node_global\bin\create-vite-app
Arguments:
Directory: D:\Program Files\nodejs\node_global
Output:
info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
下一步我就着重介绍如何把node从Program Files中移出来.
1.nodejs整个目录拷贝到D盘根目录下
D:\nodejs
2.修改node的全局环境.
1) 修改cache和global
npm config set cache "D:\nodejs\node_cache"
npm config set prefix "D:\nodejs\node_global"
2)修改系统环境变量
Path修改这两处:"D:\nodejs\"和"D:\nodejs\node_global";
NODE_PATH:D:\nodejs\node_global\node_modules
可以通过
where node命令查当前的node安装路径,
npm root -g 命令查当前node的全局安装环境
二.还是空格问题
npm config get cache
得到路径:C:\Program Files\nodejs\node_cache
“Program Files”确实带有空格
解决方案:
执行:
npm config set cache "C:\Program~1\nodejs\node_cache"--global
将带“Program Files”空格的路径改写为"Program~1"。
例如:C:\Program~1\nodejs\node_cache (这是 windows 的一种路径表达方式)
三.使用nvm更新node版本(在我的上一篇博客)
参考文章
附:重装node的时候,安装yarn途中可能还有问题,可以注意一下