错误背景
通过附加的命令行选项直接指定项目名称和你想要使用的模板。例如,要构建一个 Vite + Vue 项目,运行:
yarn create vite my-vue-app --template vue
执行了之后报错了
PS D:\code\vscodeprojects\mystudy> yarn create vite my-vue-app --template vue
yarn create v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "[email protected]" with binaries:
- create-vite
- cva
文件名、目录名或卷标语法不正确。
error Command failed.
Exit code: 1
Command: D:\environment\nvm\node_global\bin\create-vite
Arguments: my-vue-app --template vue
Directory: D:\code\vscodeprojects\mystudy
Output:
info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
报错原因
yarn
的安装包默认是在C盘的而我电脑上yarn
安装在D盘,所以就会报这样的错误。
可以使用如下命令查看当前yarn的安装包位置
yarn global dir
解决办法
1、将yarn
的全局路径改到D盘就可以了,在D盘的environment
目录下创建yarn
文件夹,然后再其中创建一个global
和cache
文件夹
2、执行如下命令
yarn config set global-folder "D:\environment\yarn\global"
yarn config set cache-folder "D:\environment\yarn\cache"
3、然后就可正常使用yarn
创建vite
项目了