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)

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尿不湿没有了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值