Yarn global installs to current directory

≡放荡痞女 提交于 2019-12-10 11:09:53

问题


I am trying to get React Native working on my Linux machine. In order to get the cli running I have run:

$ yarn global add react-native-cli

and see:

yarn global v0.16.1
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed react-native-cli@1.0.0 with binaries:
      - react-native
Done in 1.70s.

Everything installs just fine, but when I attempt to create a new React Native project, I get:

$ react-native init Test
react-native: command not found

Come to find out, yarn is installing the dependency into whatever the current directory is instead of installing it globally. Any help on this? I'm running Lubuntu 16.04.


回答1:


Edit

Now it works:

yarn config set prefix /usr/local

Check with

yarn config get prefix

Notice that only executables will be installed to this prefix location. Packages i.e. on Windows are installed in %USERPROFILE%\AppData\Local\Yarn\config\global\node_modules.

On Windows I do:

mkdir ~/yarn-global
yarn config set prefix ~/yarn-global

Old

Global path isn't configurable permanently yet. We can only read the settings:

> yarn global bin
C:\Program Files\nodejs

When I tried to install elm-upgrade, I got error in log %USERPROFILE%\AppData\Local\Yarn\config\global\yarn-error.log

Trace:
  Error: EPERM: operation not permitted, open 'C:\Program Files\nodejs\elm-upgrade.cmd'
      at Error (native)

But elm-upgrade was installed in %USERPROFILE%\AppData\Local\Yarn\config\global\node_modules\.bin.

Related:

  • Location of global bin doesn't match the doc https://github.com/yarnpkg/yarn/issues/1194


来源:https://stackoverflow.com/questions/40330759/yarn-global-installs-to-current-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!