yarn在搭建 项目时,命令行报错:The filename, directory name, or volume label syntax is incorrect. (文件名、目录

在这里插入图片描述

具体错误


yarn在搭建第一个 Vite 项目时,命令行报错:The filename, directory name, or volume label syntax is incorrect. (文件名、目录名或卷标语法不正确)

info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[
    译文:package-lock警告。json。您的项目包含由Yarn以外的工具生成的锁文件。建议不要混合使用包管理器,以避免锁文件不同步导致的解析不一致。要清除此警告,请删除package-lock.json。
]
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
error An unexpected error occurred: "EPERM: operation not permitted, unlink 'D:\\xxx'".
info If you think this is a bug, please open a bug report with the information provided in "D:\\xxx".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

错误原因


Yarn的默认安装路径在C盘,然而由于C盘空间太少,我已经把Yarn全局路径和缓存路径修改到D盘,但是我并没有修改全局可执行文件目录。由于三个路径磁盘卷标不匹配,所以会报这样的错误:The filename, directory name, or volume label syntax is incorrect.(文件名、目录名或卷标语法不正确)
使用一下命令可以查看全局路径、缓存路径和全局可执行文件目录:

查看 yarn 全局bin位置

yarn global bin

查看 yarn 全局安装位置

yarn global dir

查看 yarn 全局cache位置

yarn cache dir

解决办法


修改路径命令

改变 yarn 全局bin位置

# yarn config set prefix "D:\NodeJS\Yarn\Data"
yarn config set prefix "D:\ProgramFiles\NodeJS\Yarn\Date"

改变 yarn 全局安装位置

# yarn config  set global-folder "D:\NodeJS\Yarn\Data\global"
yarn config  set global-folder "D:\ProgramFiles\NodeJS\Yarn\Date\global"

改变 yarn 全局cache位置

# yarn config set cache-folder "D:\NodeJS\Yarn\Cache"
 yarn config set cache-folder "D:\ProgramFiles\NodeJS\Yarn\Cache"

改变 yarn 全局 link 位置

# yarn config set link-folder "D:\NodeJS\Yarn\Data\link"
yarn config set link-folder "D:\ProgramFiles\NodeJS\Yarn\Date\link"

把全局基础目录修改为D:\ProgramFiles\NodeJS\Yarn

yarn config set prefix 'D:\ProgramFiles\NodeJS\Yarn'

然后全局可执行文件目录将自动变更。我们再一次通过命令查看全局可执行文件目录:

D:\myspace> yarn global bin
D:\ProgramFiles\NodeJS\Yarn\bin

文件夹目录结构


D:.
└───yarn
    ├───bin
    ├───cache
    └───global

系统变量添加

D:\yarn\global\node_modules\bin添加系统环境变量到Path中。

(借鉴:https://segmentfault.com/a/1190000043503907#item-1)

猜你喜欢

转载自blog.csdn.net/qq_24484317/article/details/133265755