在搭建第一个 Vite 我的项目时,命令行报错:The filename, directory name, or volume label syntax is incorrect. (文件名、目录名或卷标语法不正确)
具体谬误
D:\myspace> yarn create viteyarn create v1.22.17[1/4] Resolving packages...[2/4] Fetching packages...[3/4] Linking dependencies...[4/4] Building fresh packages...success Installed "create-vite@4.1.0" with binaries: - create-vite - cvaThe filename, directory name, or volume label syntax is incorrect.error Command failed.Exit code: 1Command: C:\Users\PC\AppData\Local\Yarn\bin\create-viteArguments:Directory: D:\myspaceOutput:info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
谬误起因
Yarn
的默认装置门路在C
盘,然而因为C
盘空间太少,我曾经把Yarn
全局门路和缓存门路批改到F
盘,然而我并没有批改全局可执行文件目录。因为三个门路磁盘卷标不匹配,所以会报这样的谬误:The filename, directory name, or volume label syntax is incorrect.
(文件名、目录名或卷标语法不正确)
应用一下命令能够查看全局门路、缓存门路和全局可执行文件目录:
// 全局门路D:\myspace> yarn global dirF:\yarn\global// 缓存门路D:\myspace> yarn cache dirF:\yarn\cache\v6// 全局可执行文件目录D:\myspace> yarn global binC:\Users\PC\AppData\Local\Yarn\bin
解决办法
把全局根底目录批改为F:\yarn
yarn config set prefix 'F:\yarn'
而后全局可执行文件目录将主动变更。咱们再一次通过命令查看全局可执行文件目录:
D:\myspace> yarn global binF:\yarn\bin
最初,执行yarn create vite
即可胜利运行:
D:\myspace> yarn create viteyarn create v1.22.17[1/4] Resolving packages...[2/4] Fetching packages...[3/4] Linking dependencies...[4/4] Building fresh packages...success Installed "create-vite@4.1.0" with binaries: - create-vite - cva√ Project name: ... vite-project√ Select a framework: » Vue√ Select a variant: » TypeScriptScaffolding project in D:\myspace\vite-project...Done. Now run: cd vite-project yarn yarn devDone in 10.61s.
最终目录构造如下:
F:.└───yarn ├───bin ├───cache └───global
批改全局门路和缓存门路
// 批改全局门路yarn config set global-folder "F:\yarn\global"// 批改缓存门路yarn config set cache-folder "F:\yarn\cache"
把F:\yarn\global\node_modules\.bin
增加零碎环境变量到Path
中。
参考文档
- yarn global | Yarn
- yarn cache | Yarn
欢送关注我的微信公众号:乘风破浪的Coder