Google到了相似的问题解决方法,但是尝试后,依然无效,这里记录下自己找到的解决方法。
问题描述
使用 yarn global install @vue/cli
后,输入
vue create hello-world
,报错:
zsh: command not found: vue
Yarn 版本1.21.1。
解决方法
参考 yarn doesn’t add global packages bin/ to $PATH ,在.zshrc中添加了一行:
export PATH="$(yarn global bin):$PATH"
打开新的Tab,加载后,出现:
/Users/lucia/.zshrc: xxx: command not found: yarn
终端输入:
yarn global bin
# /Users/lucia/.asdf/installs/nodejs/12.14.0/.npm/bin
想到本地nodejs通过asdf安装的, 于是参考Using Yarn Global Packages with asdf,
终端执行:
yarn config set prefix ~/.yarn
打开 .yarnrc
文件,发现文件被追加了一行:
prefex "/Users/lucia/.yarn"
重新终端找vue:
which vue
vue not found
看来PATH还是没有配对。
最后在yarn global installs don’t get shimmed 找到了答案。
方法并不优雅,不过倒是有效。
终端:
yarn global dir
# /Users/lucia/.config/yarn/global
找到 node_module的地方,然后把这个PATH 追加到.zshrc
文件中:
export path="$HOME/.config/yarn/global/node_modules/.bin:$PATH"
OK,Bravo!
参考
yarn doesn’t add global packages bin/ to $PATH