Skip to content

Fix global module executable path on Windows - #3233

Merged
bestander merged 1 commit into
yarnpkg:masterfrom
Daniel15:module-location
Apr 24, 2017
Merged

bestander merged 1 commit into
yarnpkg:masterfrom
Daniel15:module-location

Conversation

@Daniel15

Copy link
Copy Markdown
Member

Summary
Node.js is almost always installed in C:\Program Files\Yarn, which regular users can't write to. However, Yarn defaults to installing the executables for global modules in the Node directory. This means that the out-of-the-box experience for people installing global modules on Windows is totally broken.

It should instead place them in a directory that the user can write to. I'm going with %LocalAppData\Yarn\bin (eg. C:\Users\Daniel\AppData\Local\Yarn\bin) as it makes the most sense given all the config and cache is already in that directory. I also updated the path in the installer, as the path the installer was using didn't actually exist (.bin instead of bin).

Test plan

Tested bin\yarn global add webpack, it placed the files in the right directory:

Closes #3055

@DustinKingen

DustinKingen commented Apr 23, 2017 •

Copy link
Copy Markdown

Can confirm the additional if statement fixes the issue. Not sure whether changing .bin -> bin is a breaking change. I noticed that the .bin folder is not created after installing yarn. I had to manually add the folder to AppData\Local\Yarn. Yarn will need to ensure .bin or bin exists so that scripts installed with yarn global will be available on the path.

@Daniel15

Copy link
Copy Markdown
Member Author

Not sure whether changing .bin -> bin is a breaking change

.bin never actually existed, so that should be fine.

@Daniel15

Copy link
Copy Markdown
Member Author

Just realised this is broken for non-root users on Linux too... Need to fix that as well.

test@a5cf448820fd:/tmp/lol$ /yarn-src/bin/yarn global add create-react-app
yarn global v0.24.0-0
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "create-react-app@1.3.0" with binaries:
      - create-react-app
error We don't have permissions to touch the file "/usr/bin/create-react-app".
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

@bestander
bestander merged commit 5fc8539 into yarnpkg:master Apr 24, 2017
@Daniel15
Daniel15 deleted the module-location branch April 30, 2017 02:19
@DanBuild DanBuild mentioned this pull request May 2, 2017
@gaearon

gaearon commented May 12, 2017

Copy link
Copy Markdown
Contributor

Thanks for the fix.

@wtchangdm

Copy link
Copy Markdown

Sorry for asking question here, is the PATH environment variable added only when yarn was installed by Windows Installer and not by npm?

@Daniel15

Daniel15 commented May 27, 2017 via email

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants