RootedGlobal / node-casperjs-aws-lambda

Base scaffolding app for a casperjs/phantomjs app running on Amazon (AWS) Lambda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Fatal: [Errno 2] No such file or directory; did you install phantomjs?\n"

prusanoff opened this issue · comments

Hey @narainsagar Great work,
however i am still having the same issue.
I have casper and phantom running locally just great.
however I am still getting the same issue with lambda
"Fatal: [Errno 2] No such file or directory; did you install phantomjs?\n"
I have tried to point directly at exec in the root folder and it will not open it in aws lambda
I figured it might be in the casperjs
then i have added phantom PHANTOMJS_EXECUTABLE=pathtophantom in the .env file and still no luck to get it up and running along with Casper.

After that i found that phantom was not being pushed up so i added it to the dependencies in package.json

I have logged all my directories and i did find it there however it still will not open it.

My question is where exactly is it being called how do i fix it

FYI

Im on a mac book pro

Hi @prusanoff do you have pulled the latest master? If so then you will see in index.js that the phantomjs path is already set: https://github.com/narainsagar/node-casperjs-aws-lambda/blob/master/index.js#L28

This is how we can pass the phantom path. Let me know if you're still facing the same problem after this.

Hi @narainsagar
1.) Yes I do have the latest master from git.
2.) Yes I tried setting the PHANTOMJS_EXECUTABLE inside of index.js

  •         then i made sure the file was present by using ....**it was**
    

fs.readdir('./', function(err, items) { console.log("loging out all items: ", items); });

it still did not work

  •         after i switched it to the phantom path: `/node_modules/phantomjs/bin/phantomjs/` and i added phantom as a dependency in package.json 
    

the files where present and it still did not work

After which i started to think the phantom path i am entering inside of index.js has no impact
I found where casper calls phantom /node_modules/casperjs/bin/casperjs ln 45

*THEN I Tried adding it to the .env file *

in the .env file i put PHANTOMJS_EXECUTABLE=/var/task/phantomjs

it still did not work

after I tried to add PHANTOMJS_EXECUTABLE=/var/task//node_modules/phantomjs/bin/phantomjs/

it still did not work

trying to fix it inside of index.js or adding it to the env file had zero impact

I am losing my mind here

I am having the same issue. I pulled down the zip of the master branch, ran npm install, setup, added a role and updated .env with everything, and deployed it via command line. That didn't work, said unexpected token.

So then I uploaded the zip without any modifications. I continue to get this:

2016-10-13T04:45:26.892Z    Calling casperJS: /var/task/node_modules/casperjs/bin/casperjs [ '/var/task/casperjs-script.js' ] { PHANTOMJS_EXECUTABLE: '/var/task/phantomjs' }

2016-10-13T04:45:27.172Z    Fatal: [Errno 2] No such file or directory; did you install phantomjs?

2016-10-13T04:45:27.174Z    child process exited with code 1

I'm on a macbook pro and thought that might be an issue, so I spun up an EC2 instance of Amazon Linux and still get this error.

Hey Guys, I'm now a days have some busy schedule so will look into this more before this weekend and 'll let you know further.

Thanks.

Any news on this? I have the same issues as everyone!

Thanks for the great project! :)

Yea, me too. I get the same error.

Guys, turns out it is just updating PATH environment.
Source: http://stackoverflow.com/a/40157597/1135744

Creating a pull request.

Thanks for the PR @svamja 👍

Ok guys,, I have my amazon server free tier expired.. so can you guys (i.e., anyone?) test this PR #4 and let me know here so I can merge this with the master asap..

Thanks..

I am going to merge the PR. since I also think updating PATH environment will fix this..

The issue will still remain open until someone confirm me if it fixes this or not..

Fixed in PR #4

Again many Thanks to @svamja for the PR and @MathRivest for giving the feedback (i.e., testing the PR)

H @narainsagar : using your cool project to learn Lambda. I'm also getting this error after deploying. I took a look at PR #4 and looks like things have changed a bit .. for example, there is not runner.js and utils.js. do you know if this project still runs in AWS?

Hi,, Yes I have just cleaned the code a bit.. Yes, It will run on AWS...

hi :) thanks for getting back so quickly. I can see in cloudwatch that the path isn't right, so I'll see if I can figure out why the path isn't getting set right. The log output is below.

Calling casperJS: /var/task/node_modules/casperjs/bin/casperjs [ '/var/task/src/scripts/create_screenshot_with_casper.js',
'--email=hello@hello.com',
'--password=12345' ] { PHANTOMJS_EXECUTABLE: '/var/task/bin/phantomjs' }

I doubt it matters, but I had to change nodejs to nodejs4.3 in .env

I added logging to print out the path .. it is showing "/var/task/node_modules/phantomjs/bin/phantomjs" but is failing with the fs.existsSync(phantomPath) in utils.js .. would it matter if I'm building on a Mac and deploying to Lambda?

there's check for if it's not find phantomjs executable in node_modules then it will use local from bin/ folder.

did you create your "create_screenshot_with_casper.js" script inside scripts/ directory? confirm?

also share log's full screenshot...!

yes, I created the screenshot script and it is in scripts.

lambda

Something's wrong.. See if there's phantomjs/ directory inside node_modules/ directory..? If you did $ npm install then it should have to be there..!

it exists locally after I ran npm install ... I'm not sure how to check if it exists in Lambda. I'll need to investigate how to do that.

Also, confirm If this running locally on your machine? or not..

and confirm your Node version needs to be > 4.0 and npm > 3.0.

yes, it is running locally.

$ node --version
v6.8.0
$ npm --version
3.10.8

also, I see this when I "npm run deploy"

Warning!!! You are building on a platform that is not 64-bit Linux (darwin.x64). If any of your Node dependencies include C-extensions, they may not work as expected in the Lambda environment.

same error after updating node/npm and running from Ubuntu 64-bit

I see that the node_modules version of phantomjs is used when running locally.

$ npm --version
4.0.5
$ node --version
v7.4.0

I unzipped the lambda.zip and can see the TASK_ROOT/bin/phantomjs but the node_modules/phantomjs doesn't exist

it is able to find phantom if I manually add the /var/run/task/bin directory to path in runner.js like this

process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'] + ':/var/task/bin';

Weired.. But it's already set there in phantom path.. If you can please log & verify casperPath and phantomOptions in runner.js file..

FYI: For now, You can use like you did above i.e., manually adding ':/var/task/bin' to PATH. I will look into this once I'll get free with other stuff's.

Thanks.

Was this ever resolved? I am also having this issue now when I try this solution.

Node: v6.10.2
npm: 3.10.10

Modifying that line as @lhammond did get the thing to have the right directory in the AWS error log for phantom, but it still threw [error 2].

Hi @50shadesofwhey same error? please share screenshot or log (if possible)?

@narainsagar here is my log:

START RequestId: 492f21b5-2501-11e7-b994-8940665865ec Version: $LATEST
2017-04-19T13:08:32.799Z 492f21b5-2501-11e7-b994-8940665865ec Running index.handler
2017-04-19T13:08:32.799Z 492f21b5-2501-11e7-b994-8940665865ec ==================================================
2017-04-19T13:08:32.799Z 492f21b5-2501-11e7-b994-8940665865ec event { key3: 'value3', key2: 'value2', key1: 'value1' }
2017-04-19T13:08:32.980Z 492f21b5-2501-11e7-b994-8940665865ec ==================================================
2017-04-19T13:08:32.980Z 492f21b5-2501-11e7-b994-8940665865ec Executing file named: sample-script.js with parameters: {"email":"hello@hello.com","password":"12345"}
2017-04-19T13:08:32.980Z 492f21b5-2501-11e7-b994-8940665865ec ==================================================
2017-04-19T13:08:32.981Z 492f21b5-2501-11e7-b994-8940665865ec PATH /usr/local/lib64/node-v4.3.x/bin:/usr/local/bin:/usr/bin/:/bin
2017-04-19T13:08:32.981Z 492f21b5-2501-11e7-b994-8940665865ec PATH /usr/local/lib64/node-v4.3.x/bin:/usr/local/bin:/usr/bin/:/bin:/var/task2017-04-19T13:08:32.981Z 492f21b5-2501-11e7-b994-8940665865ec Calling casperJS: /var/task/node_modules/casperjs/bin/casperjs [ '/var/task/src/scripts/sample-script.js',
'--email=hello@hello.com',
'--password=12345' ] { PHANTOMJS_EXECUTABLE: '/var/task/node_modules/phantomjs/bin/phantomjs' }
2017-04-19T13:08:33.318Z 492f21b5-2501-11e7-b994-8940665865ec Fatal: [Errno 2] No such file or directory; did you install phantomjs?

2017-04-19T13:08:33.321Z 492f21b5-2501-11e7-b994-8940665865ec child process exited with code 1
2017-04-19T13:08:33.357Z 492f21b5-2501-11e7-b994-8940665865ec ==================================================
2017-04-19T13:08:33.357Z 492f21b5-2501-11e7-b994-8940665865ec Stopping index.handler
2017-04-19T13:08:33.357Z 492f21b5-2501-11e7-b994-8940665865ec ==================================================
END RequestId: 492f21b5-2501-11e7-b994-8940665865ec

I had the same problem and fixed by using @narainsagar tip. So modify runner.js to

if (process.env['LAMBDA_TASK_ROOT']) {
    process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'] + ':/var/task/bin';
}

Thanks for this awesome lib :)!

@pjmuller OMG thank you! I've been trying things for weeks now! This fixed it.

@pjmuller @50shadesofwhey Thanks for your feedback and support It is now available in latest release 1.0.2