Medium / phantomjs

NPM wrapper for installing phantomjs
Other
1.42k stars 436 forks source link

request-progress #793

Open loushou opened 6 years ago

loushou commented 6 years ago

So this is more informative, than a request for support. I spent quite some time trying to figure out what the hell was going on, so I wanted to share with everyone, in the hopes that it will solve someone's issue in a shorter time than it took me to realize.

Like many others who have written bug reports on this project, I was running into this problem:

$ npm install
> phantomjs-prebuilt@2.1.16 install /var/www/wordpress/frontends/node_modules/phantomjs-prebuilt
> node install.js

internal/modules/cjs/loader.js:550
    throw err;
    ^

Error: Cannot find module 'request-progress'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
    at Function.Module._load (internal/modules/cjs/loader.js:475:25)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at Object.<anonymous> (/docker/externals/node/frontends/phantomjs-prebuilt/install.js:9:23)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-04-27T14_07_45_176Z-debug.log

Basically this error is saying that it could not build the phantomjs package, because the request-progress package is missing (this also happens with the 'throttleit' package missing too). Even manually installing the package made no difference. NPM says 'yeah ok I installed it', but then immediately fails to build phantomjs again. When you check for the dir inside of node_modules, it still shows no request-progress dir, even though NPM said it was added.

Racking my brain for hours, I tried a TON of different things. I mean my whole setup is inside of a build script for Elastic Beanstalk, that runs everything inside a docker container... so there are a bunch of variables that could have been affecting the build/install. After eliminating almost everything else, I decided to look into NPM being the source of the problem.

Without boring you with all the details, the problem was a symlink. Being on Elastic Beanstalk, inside a docker, I was trying to cut down on non-new-instance deploy time. My solution for this was to symlink the node_modules directory, and run npm install (or even yarn install) from the dir with package.json and the symlinked node_modules. That way on subsequent deploys, I would not have to redownload all the packages and rebuild them all, but rather only make the changes, if any, like adds and deletes. Seemed like it should work, and save deploy time.

The problem is, it does not work. For some reason, MOST packages are ok with this symlink. They read right through it like it was just another dir. BUT, it seems like several of the dependency packages of phantomjs-prebuilt (like request-progress and throttleit) have major trouble with this during installation. I do not know the technical details of why, because I wasted a ton of time just trying to get it to work, but I know for a 100% fact that when I ran npm install (or yarn install) from a context that was not through a symlink, everything worked without a problem.

The bottom line is this: If you are running into a problem with this package, and that problem happens to be related to some of it's dependencies being missing... MAKE SURE you are NOT going through a symlinked dir to install them. Make sure that your package.json is directly adjacent to a DIRECTORY called node_modules, not a symlink.

I hope this helps someone. Also, if anyone has any time to track down the technical reasons for this, I am sure that the community would be grateful for the explanation, after all, we are pretty much all the sorts who have to know :)