I have an application which is using phantom js and nodejs app. I am using several node modules in that node app, which is run through phantom js. I need to use amazon node aws-sdk. I installed it with
npm install aws-sdk
that node app is able to find that once i do this
var AWS = require('aws-sdk');
but it start prompting errors for other native node js modules, three of them specifically, 'crypto', 'timers', 'path'. I checked /usr/lib/nodejs folder and those are there, so how come phantomjs node app is unable to find them? specific errors
Error: Cannot find module 'crypto'
phantomjs://platform/bootstrap.js:299 in require
phantomjs://platform/bootstrap.js:263 in require
phantomjs://platform/util.js:4
TypeError: undefined is not a function (evaluating 'AWS.util.update')
phantomjs://platform/core.js:16
Error: Cannot find module 'path'
phantomjs://platform/bootstrap.js:299 in require
phantomjs://platform/bootstrap.js:263 in require
phantomjs://platform/api_loader.js:3
Error: Cannot find module 'events'
phantomjs://platform/bootstrap.js:299 in require
phantomjs://platform/bootstrap.js:263 in require
phantomjs://platform/xml2js.js:12
phantomjs://platform/xml2js.js:538
TypeError: undefined is not an object (evaluating 'AWS.XML.Parser = require('./xml/node_parser')')
it does work fine if i directly go to node shell and do require('aws-sdk'). i run node app from phantomjs like this
phantomjs test.js
or
/usr/bin/phantomjs test.js
it just doesn't work with phantomjs, any idea and help would be appreciated here.
PhantomJS is not compatible with node.js.
When you run it like
/usr/bin/phantomjs test.js
you run a script inside of PhantomJS.
If you want to launch a node.js app from PhantomJS, you can use exec or spawn methods to do it, see this answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With