seansfkelley / yerna

A Lerna-like tool for managing Javascript monorepos using Yarn
Other
142 stars 10 forks source link

Error spawn yarn ENOENT when yerna install on windows 10 with node v7.5.0 #13

Open jogelin opened 7 years ago

jogelin commented 7 years ago

I am trying to make yerna working on my environment (very interested by a minimalist lerna like). I am under windows 10 (not my choice). I already had an issue when installing yerna globally (you need to run your terminal as an admin).

And now I simply want to install my packages :

$ yerna install
yerna: running yarn install for 3 package(s)
yerna: linking all 3 package(s) before running tasks
yerna: Error: spawn yarn ENOENT
yerna:     at exports._errnoException (util.js:1023:11)
yerna:     at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
yerna:     at onErrorNT (internal/child_process.js:359:16)
yerna:     at _combinedTickCallback (internal/process/next_tick.js:74:11)
yerna:     at process._tickCallback (internal/process/next_tick.js:98:9)
yerna: unexpected error, exiting suddenly!
yerna: this is probably a bug in Yerna itself, please file an issue!
yerna: NOTE: package.jsons or links may be in an inconsistent state
yerna: NOTE: child processes may be abandoned
internal/child_process.js:389
      throw errnoException(err, 'kill');
      ^

Error: kill EINVAL
    at exports._errnoException (util.js:1023:11)
    at ChildProcess.kill (internal/child_process.js:389:13)
    at process.killOnExit (C:\Users\JGE\AppData\Local\Yarn\config\global\node_modules\yernapkg\lib\yarn-with-package-json-mangling.js:56:11)
    at emitOne (events.js:101:20)
    at process.emit (events.js:189:7)
    at process.exit (internal/process.js:147:15)
    at process.logAndDie (C:\Users\JGE\AppData\Local\Yarn\config\global\node_modules\yernapkg\lib\error-handling.js:20:13)
    at emitOne (events.js:96:13)
    at process.emit (events.js:189:7)
    at process._fatalException (bootstrap_node.js:292:26)

I read some stuff about that yarn counld be not found in the PATH but I added all possible paths and yarn works globally but not yerna...

Can you help me ?

jogelin commented 7 years ago

If I modify the file yarn-with-package-json-mangling.js :

line 53 : const child = child_process.spawn('yarn, args, spawnArgs);
to
line 53 : const child = child_process.spawn('yarn.cmd', args, spawnArgs);

it works !

I am not at all an expert in node process but do you know why under windows the simple yarn command doesn't work but it found the .cmd in the path ?

seansfkelley commented 7 years ago

Hey! Happy to hear you're interested. :) I noticed that Lerna uses cross-spawn rather than straight child_process.spawn for this type of thing. Unfortunately I don't have access to a good Windows dev environment, but if you're already poking around the code, would you mind swapping the calls to spawn out with cross-spawn? It claims to be a drop-in replacement, and if it works for you, I can make that change.

Edit: there are also some docs on Windows + spawn + .cmd that might explain what's happening (maybe we have to use the shell option?).

seansfkelley commented 7 years ago

Hm, it also looks like it's failing to find Yarn, aborting, and then failing to abort and dying hard when it tries to kill child processes. Not sure what that's about, nothing jumps out in the child_process docs about Windows + kill.

jogelin commented 7 years ago

Indeed, it still doesn't work :

yerna: running yarn install for 2 package(s)
yerna: Error: spawn yarn ENOENT
yerna:     at exports._errnoException (util.js:1022:11)
yerna:     at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
yerna:     at onErrorNT (internal/child_process.js:359:16)
yerna:     at _combinedTickCallback (internal/process/next_tick.js:74:11)
yerna:     at process._tickCallback (internal/process/next_tick.js:98:9)
yerna: unexpected error, exiting suddenly!
yerna: this is probably a bug in Yerna itself, please file an issue!
yerna: NOTE: package.jsons or links may be in an inconsistent state
yerna: NOTE: child processes may be abandoned
yerna: failed after 0.02s
internal/child_process.js:389
      throw errnoException(err, 'kill');
      ^

Error: kill EINVAL
    at exports._errnoException (util.js:1022:11)
    at ChildProcess.kill (internal/child_process.js:389:13)
    at process.killOnExit (C:\Users\Joni\AppData\Roaming\npm\node_modules\yernapkg\lib\yarn-with-package-json-mangling.js:58:11)
    at emitOne (events.js:101:20)
    at process.emit (events.js:188:7)
    at process.exit (internal/process.js:147:15)
    at process.logAndDie (C:\Users\Joni\AppData\Roaming\npm\node_modules\yernapkg\lib\error-handling.js:20:13)
    at emitOne (events.js:96:13)
    at process.emit (events.js:188:7)
    at process._fatalException (bootstrap_node.js:292:26)

I don't really know how to help you but I can continue to test on my (fu..) windows environment ;-p

Today, for my company, I am trying to setup 2 repos :

And it's not easy to synchronize all of this stuff locally with links, packaging, etc.. You can find a poc here if you want more info.

jogelin commented 7 years ago

Another remark, why yerna is trying to find the packages folder at the git root ?

seansfkelley commented 7 years ago

The location of packages is just a simplifying assumption it makes, in mimicry of original Lerna behavior (though that has since become configurable in Lerna).

As for the command failing, there's not a whole lot I can do. It looks like there are at least two ways to install Yarn on Windows and I don't know anything about the intricacies of the Windows shell environment in order to know what the .cmd extension implies about your environment and/or the way that Yerna is trying to invoke commands. A quick look at Lerna shows that it doesn't appear to do anything special when invoking npm under the name npm except to use cross-spawn, which evidently doesn't help.

seansfkelley commented 7 years ago

Looks like the .cmd thing is expected: https://stackoverflow.com/questions/17516772/using-nodejss-spawn-causes-unknown-option-and-error-spawn-enoent-err. Lerna's ChildProcessUtilities seems to use execa for this task, perhaps that's the proper solution to do this simply and safely?