alexanderGugel / ied

:package: Like npm, but faster - an alternative package manager for Node
http://alexandergugel.github.io/ied
MIT License
1.99k stars 53 forks source link

lifecycle scripts race condition #100

Closed kirbysayshi closed 8 years ago

kirbysayshi commented 8 years ago

Using the real-world (ish) package.json found here: https://gist.github.com/kirbysayshi/8b32f5ae77898475f0ee172e0452d713, ied fails to install with the following error:

$ ied install
module.js:338
    throw err;
          ^
Error: Cannot find module 'hawk'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/private/tmp/ied-test/node_modules/756151e61e615e807a3e1ae03f2340a325ed3501/request.js:10:12)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
/Users/drewp/nvm/versions/node/v0.12.7/lib/node_modules/ied/bin/cmd.js:57
          throw err
                ^
Error: Command node install.js ended with code 1
    at ChildProcess.<anonymous> (/Users/drewp/nvm/versions/node/v0.12.7/lib/node_modules/ied/lib/run.js:19:68)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

This is using ied master as of today (https://github.com/alexanderGugel/ied/commit/54aff07790bb6ffa15e972e06c1ea62b41325503).

Doing some digging, and putting in some print statements indicates that this is caused by a require('hawk') via require('request'), ultimately during the install script defined in phantomjs-prebuilt.

Seems like a race condition, where hawk is still in the process of being downloaded when lifecycle scripts begin executing.

The package.json is an edited version of an internal codebase, and is very much a real-world scenario that I assume ied (as an npm replacement) would want to be able to handle.

Not sure how best to describe this, so feel free to edit the title of this issue. Also, thanks for creating a great tool, I can't wait to start using it for real!

impronunciable commented 8 years ago

I'm experimenting the same issue. Some subdependencies are not yet downloaded and the parent module attemps to run the install script.

alexanderGugel commented 8 years ago

This is due to circular dependencies not being resolved properly and other edge cases in the dependency graph. It's fixed on the rebirth branch, which will be merged into master in a couple of days.

impronunciable commented 8 years ago

It works. Thank you!

alexanderGugel commented 8 years ago

Closing, since it's now finally merged into master. Lifecycle scripts can be activated using --build.