yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.44k stars 2.73k forks source link

Relative path issue Win10/CYGWIN #4194

Open KevinBatdorf opened 7 years ago

KevinBatdorf commented 7 years ago

Do you want to request a feature or report a bug? Report a bug.

What is the current behavior? yarn install fails with this error:

Cloning into 'C:\Users\Kevin\AppData\Local\Yarn\cache\v1\.tmp\d467663531f204616cf61ecefbe7254c'...
fatal: Invalid path '/home/Kevin/Code/theNextFacebook/C:\Users\Kevin\AppData\Local\Yarn\cache\v1\.tmp\d467663531f204616cf61ecefbe7254c': No such file or directory

which appears to be a relative path issue.

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

Windows 10

$ uname
--> CYGWIN_NT-10.0
$ yarn --version
--> 0.27.5
$ which yarn
--> /usr/local/bin/yarn
$ node -v 
--> v6.11.2
$ which node
--> node: aliased to /cygdrive/c/"Program Files"/nodejs/node
arcanis commented 7 years ago

Hm unfortunately none of us work on cygwin, so a PR would be helpful

Daniel15 commented 7 years ago

This might be Cygwin + Windows Git not playing well together. Try installing Cygwin Git and see if that helps.

Even better: If possible, you should totally ditch Cygwin and instead use Windows Subsystem for Linux. It's much smoother and you get a legit Linux environment (powered by Ubuntu) rather than a half-Linux-half-Windows cross-compiled hybrid like Cygwin 😛 .

KevinBatdorf commented 7 years ago

Unfortunately the PC I have this on is the Enterprise version of Windows which doesn't have that Creator's update yet with the Linux subsystem =/

It's not critical though that I fix this, but in case someone else needs too, here's what I discovered so far. I'm also not well-versed in NodeJS, although I definately enjoyed learning how Yarn works.

I think the issue is with using NodeJS's file functions like how:

this.cwd = this.config.getTemp(crypto.hash(this.gitUrl.repository));

will use

this.tempFolder = opts.tempFolder || path.join(this.cacheFolder, '.tmp');

and ultimately

// not a strict polyfill for Node's fs.mkdtemp
export async function makeTempDir(prefix?: string): Promise<string> {
  const dir = path.join(os.tmpdir(), `yarn-${prefix || ''}-${Date.now()}-${Math.random()}`);
  await unlink(dir);
  await mkdirp(dir);
  return dir;
}

I couldn't figure out how to set that opts.tempFolder actually. Is that possible?

Anyway, I got a lot of it to work by hard-coding directories in there, but then I got stuck on

if (await fs.exists(cwd)) {
  await spawnGit(['pull'], {cwd});
} else {
  await spawnGit(['clone', gitUrl.repository, cwd]);
}

which would return false, attempt to pull in the repo and fail as the directory isn't empty. That's when I decided to move on with my life :D

arcanis commented 7 years ago

I couldn't figure out how to set that opts.tempFolder actually. Is that possible?

It should just be a matter of adding --temp-folder inside your command line or a yarnrc file, along with a linux-style path. I think the issue here is that os.tmpdir() is returning a Windows path, but the path functions are operating on linux-style paths (where C: is a valid directory name) :/

KevinBatdorf commented 7 years ago

A workaround for someone else in my position. Set up a virtual machine with Vagrant and Virtualbox and put /home/Kevin/code as a shared folder, ssh into the virtual machine and run yarn install from there without issue.

I used Laravel Homestead

dvillarama commented 6 years ago

I hit this issue today. My solution was to uninstall git from cygwin and use the git from chocolatey.

My theory is that the git install using chocolatey understands windows path while cygwin's version does not.

Daniel15 commented 6 years ago

git install using chocolatey understands windows path while cygwin's version does not.

Cygwin's version uses their POSIX conversion layer, which can sometimes do strange things to paths as it needs to support both "Windows-style" and "Unix-style" paths. The version installed via Chocolatey is likely the MinGW/msys compiled version, which is closer to native.

nklayman commented 6 years ago

I tried this on the Windows Linux Subsystem on Ubuntu as well and got the same error. Yarn error log attached. yarn-error.log

markwoon commented 5 years ago

This still doesn't work with yarn 1.13.0.

Setting --cache-folder doesn't work either. For example, setting it to /tmp just produces:

fatal: Invalid path '/home/Kevin/Code/theNextFacebook/C:\foo\.tmp\d467663531f204616cf61ecefbe7254c': No such file or directory