Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When installing global modules, Yarn tries to create .cmd file in wrong directory #2192

Closed
gaearon opened this issue Dec 8, 2016 · 44 comments

Comments

@gaearon
Copy link
Contributor

gaearon commented Dec 8, 2016

What is the current behavior?

Yarn fails to install create-react-app:

C:\Users\gaearon>yarn global add create-react-app
yarn global v0.17.10
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed [email protected] with binaries:
      - create-react-app
error An unexpected error occurred: "EPERM: operation not permitted, open 'C:\\Program Files\\nodejs\\create-react-app.cmd'".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\gaearon\\AppData\\Local\\Yarn\\config\\global\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

I have no such problem with npm:

C:\Users\gaearon> npm i -g create-react-app
C:\Users\gaearon\AppData\Roaming\npm\create-react-app -> C:\Users\gaearon\AppData\Roaming\npm\node_modules\create-react-app\index.js
C:\Users\gaearon\AppData\Roaming\npm
`-- [email protected]
  ...

If the current behavior is a bug, please provide the steps to reproduce.

yarn global add create-react-app

What is the expected behavior?

It gets installed.

Please mention your node.js, yarn and operating system version.

Node 6.9.2
Yarn 0.17.10
Windows 10 Enterprise 10.0.14393 Build 14393

Yarn log

https://gist.github.com/gaearon/e67437d7a4102fe696a34dec2c7fe825

@gaearon
Copy link
Contributor Author

gaearon commented Dec 8, 2016

If you work at FB you can repro this with a loaner Windows laptop.

@Mikeysauce
Copy link

This is an issue with all global installs on windows in my experience. #1324 (comment) is the effect and the solution. I noted that the path generated in the example.cmd file is incorrect whilst the path in the example.cmd.cmd is correct, hence deleting and renaming fixes this bug.

@Daniel15
Copy link
Member

Daniel15 commented Dec 9, 2016

Really bizarre, it's trying to write the file to C:\Program Files\Nodejs instead of in %LocalAppData% (C:\Users\gaearon\AppData\Local\ in your case). I remember seeing another issue about this. You can't write to C:\Program Files without escalating the process to admin rights, so it's the wrong place to put these files. From memory, they should actually be ending up in %LocalAppData%\Yarn\

@Daniel15 Daniel15 changed the title "yarn global add create-react-app" fails on Windows When installing global modules, Yarn tries to create .cmd file in wrong directory Dec 9, 2016
@juvasquezg
Copy link

The same with react-native

yarn global add react-native-cli

with

react-native --version

and I get "$basedir/../../Users/juvasquezg/AppData/Local/Yarn/config/global/node_modules/.bin/react-native.cmd" "$@"

the system cannot find the path specified

Go to C:\Program Files\nodejs and I saw:

  • react-native
  • react-native.cmd
  • react-native.cmd.cmd

The fix is to delete react-native.cmd and rename react-native.cmd.cmd to react-native.cmd

The Solution #1324 (comment)

@neojp
Copy link

neojp commented Feb 4, 2017

I've noticed that installing a global package works when using Powershell instead of Cmd. Binaries are saved on %LocalAppData%\Yarn\config\global\node_modules\.bin.

The only problem I noticed is that the Windows Installer sets the wrong PATH to %LocalAppData%\Yarn\.bin. It's alsos after the NPM path %AppData%\npm which overrides access to any duplicated binaries installed through there.

This could be easily addressed by fixing the PATH in the Windows Installer and adding a note for Windows usage in the docs stating that it's only compatible with PowerShell.

Is the Windows Installer in a different repo? I wouldn't mind sending a PR with these changes.

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 21, 2017

2017-02-20 1
powershell

@juvasquezg I don't have yarn installed on my system and I get the same error when running create-react-app to create a boilerplate app. when running the create-react-app command on a cmd window, the windows disappears when the command fails. I only see the error when I run the command in powershell.

I see the create-react-app command is looking for some command file in a yarn directory which does not exit since yarn is not installed on my system.

@gaearon
Copy link
Contributor Author

gaearon commented Feb 21, 2017

I see the create-react-app command is looking for some command file in a yarn directory which does not exit since yarn is not installed on my system.

I think this is because you previously installed create-react-app with Yarn, so that's likely where the installation points to. Try running npm install -g create-react-app to reinstall it with npm.

@dcu-sharepoint
Copy link

done; don't work

@gaearon
Copy link
Contributor Author

gaearon commented Feb 21, 2017

What do you get if you run Get-Command create-react-app?

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 21, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 21, 2017

This looks like it doesn't point to Yarn directory anymore.
So what exactly gets printed when you run create-react-app myapp?

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 21, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 21, 2017

Okay, maybe this command actually contains the path inside.
Can you figure out where create-react-app is currently located, and then delete the command?

Our goal is to break create-react-app completely so that it doesn't try to run the Yarn version.
Then we can try reinstalling it.

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 21, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 21, 2017

What about that C:\Program Files\nodejs\... path you mentioned in another issue? (I'm not sure how it finishes, but I'm assuming there's create-react-app script somewhere inside.)

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 21, 2017 via email

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 21, 2017 via email

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 21, 2017 via email

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 21, 2017 via email

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 22, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 22, 2017

Well, the whole permise of npm ecosystem is you don't really know what you're installing. It's by design, and Yarn does not change this behavior by default since most users consider installing arbitrary packages a feature.

The reason it didn't clean up after itself is the bug described in the very beginning of this issue. That is not intentional, and you’re welcome to help fix it if you want to. It’s an open source project after all.

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 22, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 22, 2017

what is the process of fixing this???????

You can file a new issue in this project, and describe the problem (i.e. "Yarn shouldn't require permissions for installing packages on Windows"). If npm behaves differently, the Yarn behavior could either be an oversight, or it could be a deliberate decision (e.g. to fix some other problem).

I hope this helps!

@gaearon
Copy link
Contributor Author

gaearon commented Feb 22, 2017

the create-react-app is installed in two places, on the administrator's folder and the user's folder in addition to putting crap on the nodejs folder, what the hell, makes create-react-so special... it's supposed to be a boilerplate utility for crying out loud.

Nothing makes it special, it's just an npm package. Your complaint is about how Yarn and npm install packages. It may be a bug in Yarn, or it may be something else. It's definitely not related to Create React App in any way because it has no control over the installation process, and doesn't get any special treatment from either Yarn or npm.

@Daniel15
Copy link
Member

@dcu-sharepoint, please avoid using excessive capital letters. You can make text bold if you write your comments on GitHub rather than via email :)

ESPECIALLY WHEN THE INSTALL PUTS THESE FILE WITHOUT ANY WARNING NOR DOES IT REQUEST PERMISSION WHEN THEY ARE INSTALLED EVEN THOUGH THE ACCOUNT BEING USED TO INSTALL THESE FILES IS A NON-ADMIN ACCOUNT AND WITHOUT PERMISSION TO TOUCH/INSTALL/DELETE/REMOVE/ADD ANYTHING TO THE SYSTEM FILES.

@dcu-sharepoint - There's no way to bypass Windows' directory permissions... It's likely that the Node.js directory is writable for your user or something similar, or you're running your command prompt as administrator. Alternatively, UAC File Virtualization (eg. https://blogs.msdn.microsoft.com/oldnewthing/20150902-00/?p=91681) could be kicking in and the files may actually be going to %LocalAppData%\VirtualStore\Program Files (x86).

It's by design, and Yarn does not change this behavior by default since most users consider installing arbitrary packages a feature.

@gaearon - It's a pretty bad design choice IMO, and I'm hoping that we get proper integrity verification for packages in the future. People tend to go for convenience rather than security, which isn't always the best tradeoff. This is one of the major reasons why every installation method for Yarn (tarball/installer, Debian/Ubuntu package, Windows installer) has integrity verification of some sort. The tarball and Debian package are signed using GPG< and the Windows installer has an Authenticode signature.

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 22, 2017 via email

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 22, 2017 via email

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 22, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 22, 2017

@dcu-sharepoint Sorry but what you’re claiming is just incorrect. Whatever the problem is, it’s entirely unrelated to create-react-app because it’s just an npm package and has zero control over how it gets installed.

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 22, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 23, 2017

I will try to reproduce the issue, I'm not disputing it exists (we are discussing it in an open issue about this exact problem after all 😉 ).

All I’m saying is that your diagnosis is incorrect:

I stated multiple times that YARN is not the problem, create-react-app is

This is not a Create React App problem because it doesn’t manage its own installation. It is a Yarn bug, which is why we are discussing it in the Yarn repo.

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 23, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 23, 2017

however, yarn IS NOT installed on the system i'm working with now

I assumed it is, judging by the path you provided: \Users\Carlos\AppData\Local\Yarn\. This is the path used by Yarn so I assumed you had it installed. If you still have issues with Create React App that are reproducible without Yarn, please do file a new issue in Create React App repo, and I’ll be happy to take a look.

@gaearon
Copy link
Contributor Author

gaearon commented Feb 23, 2017

Just to clarify this point:

I hate to disagree with you, the problem is not yarn, the problem is the installer used by create-react-app.

Create React App has no installer. npm works slightly differently from how you might be used to, from example, in Windows ecosystem.

create-react-app is an npm package. It doesn’t have its own installer. It doesn’t even have any code that runs on your computer until you run create-react-app yourself. There is no post-install code in it.

This is why you need either npm or Yarn to install create-react-app. It can’t install itself, and doesn’t write any files to any system directories.

So far, the problems you encountered seem to occur before running create-react-app. You never really ran create-react-app itself because of the corrupted installation (and thus a wrong path). This is as much as I can diagnose from the logs you provided.

I assumed you were using Yarn to install it (with yarn global add create-react-app) judging by your logs. If this is not the case, please explain how exactly you installed create-react-app so that I can better understand the issue.

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 24, 2017 via email

@dcu-sharepoint
Copy link

dcu-sharepoint commented Feb 24, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Feb 24, 2017

after all of this, my team procured a different windows 10 laptop with none of this software in it, my team then installed node using the node.msi downloaded from the node site, updated npm to version 4 and then executed the npm install -g create-react-app to install the create-react-app which reproduces the problem.

Well, in this case it shows that this is just how npm works 😉 . You can bring up your concerns with npm in this repo: https://github.com/npm/npm.

@gaearon
Copy link
Contributor Author

gaearon commented Feb 24, 2017

In other words, you can run npm install -g with any other package, and it will be installed in the same folder. For example, npm install -g grunt will install grunt in the same place, demonstrating it is not an issue with create-react-app.

@thezanke
Copy link

thezanke commented Feb 25, 2017

I believe I am having a similar issue... On windows (in git bash) I ran yarn global add create-react-app and when I tried to use it I get the following:

/bin/sh: /c/Program Files/nodejs/../../Users/thezanke/AppData/Local/Yarn/config/global/node_modules/.bin/create-react-app: No such file or directory

Strangely enough I was able to directly run that file myself, and it did exist. (Using the exact same full path starting at /c/Program Files except I had to add a \ before the space)

I ran npm i -g grunt per your suggestion, @gaearon, and was able to run grunt in git bash successfully. I then did yarn global add gulp to see if it's just Yarn; when I tried to run gulp I got the same message:

/bin/sh: /c/Program Files/nodejs/../../Users/thezanke/AppData/Local/Yarn/config/global/node_modules/.bin/gulp: No such file or directory

So there is something happening with yarn (most likely my fault, I admit).

When I tried to yarn global remove create-react-app && npm i -g create-react-app and then use it I got a different but similar error:

bash: /c/Program Files/nodejs/create-react-app: No such file or directory

Very curious...

I don't know if any of this helps narrow anything down but if there's anything I can do let me know!

PS: This is what I get for being too lazy to get my mac out of my bag and hook it up.

@dcu-sharepoint
Copy link

dcu-sharepoint commented Mar 19, 2017 via email

@gaearon
Copy link
Contributor Author

gaearon commented Mar 19, 2017

if that were the case other apps would do the same and not just the create-react-app

As I already mentioned exactly the same thing happens with any other Node module you install globally if it has a bin script. I explained this in #2192 (comment).

@dcu-sharepoint
Copy link

dcu-sharepoint commented Mar 19, 2017 via email

@Daniel15
Copy link
Member

Submitted a pull request to fix this: #3233

@voxsim
Copy link
Contributor

voxsim commented Apr 28, 2017

@bestander @Daniel15 maybe we can closw this or am i wrong? O.o

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

No branches or pull requests

9 participants