Node js and phantomjs - Unable to find weak module

I am running 64 bit on Linux Mint 16 'petra', and I am trying to use "phantomjs" for the first time with node js.

I installed phantomjs globally:

sudo npm install -g phantomjs 

... and confirmed that it is running (I get a phantomjs request by running "phantomjs" in the terminal)

and I installed the node 'phantom module in my node project:

 npm install phantom 

So far so good.

However, in my application code, as soon as it tries to execute this line:

 var phantom = require('phantom'); 

... the program crashes with the following trace:

  Listening on port 3000
 about to instantiate phantom module ...
 module.js: 333
     throw err;
           ^
 Error: Cannot find module 'weak'
     at Function.Module._resolveFilename (module.js: 331: 15)
     at Function.Module._load (module.js: 273: 25)
     at Module.require (module.js: 357: 17)
     at require (module.js: 373: 17)
     at new D (/ home / joe / Documents / My Stuff / Programming / Angular.js Projects / NodeJS Messing / FreeAgentScraper / node_modules / phantom / node_modules / dnode / index.js: 28:20)
     at module.exports (/ home / joe / Documents / My Stuff / Programming / Angular.js Projects / NodeJS Messing / FreeAgentScraper / node_modules / phantom / node_modules / dnode / index.js: 8: 12)
     at / home / joe / Documents / My Stuff / Programming / Angular.js Projects / NodeJS Messing / FreeAgentScraper / node_modules / phantom / phantom.js: 135: 13
     at Server.handler (/ home / joe / Documents / My Stuff / Programming / Angular.js Projects / NodeJS Messing / FreeAgentScraper / node_modules / phantom / node_modules / shoe / index.js: 22: 9)
     at Server.EventEmitter.emit (events.js: 104: 17)
     at App.emit (/ home / joe / Documents / My Stuff / Programming / Angular.js Projects / NodeJS Messing / FreeAgentScraper / node_modules / phantom / node_modules / shoe / node_modules / sockjs / lib / sockjs.js: 182: 27)
     at Session.emit_open (/ home / joe / Documents / My Stuff / Programming / Angular.js Projects / NodeJS Messing / FreeAgentScraper / node_modules / phantom / node_modules / shoe / node_modules / sockjs / lib / transport.js: 107: 23)

I can confirm that there is actually no "weak.js" in the project.

I ran 'npm install' to make sure all dependencies are installed.

A Google search showed nothing useful. Can anyone offer any advice?

+6
source share
3 answers

I had the same problem using node.js and phantom on a Windows machine, and I found that you need some special treatment in a Windows environment. npm doc here .

 var phantom = require('phantom'); phantom.create(function(ph) { return ph.createPage(function(page) { return page.open("http://www.google.com", function(status) { console.log("opened google? ", status); return page.evaluate((function() { return document.title; }), function(result) { console.log('Page title is ' + result); return ph.exit(); }); }); }); }, { dnodeOpts: {weak: false} }); 

phantom.create notification (function, parameters, callback), and here parameters use dnodeOpts: {weak: false}

+17
source

Have you installed build-essential on your system? Because weak is a module that needs to be compiled locally. I got it working on an Ubuntu system a week ago by installing build-essential ( sudo apt-get install build-essential ), but now when I try to use Linux Mint, it gives me the same error you get. During npm install -g phantom it warns that weak 0.3.1 cannot be installed.

Did you find any solution?

EDIT

And by the way, the key difference between the system in which I was successful and the current one is that the first one was 32 bits, the last one where it fails is 64 bits. Does the module have “weak” problems that prevent it from being installed on a 64-bit box?

WORKING DECISION

I solved this by following these steps:

  • sudo add-apt-repository ppa:fkrull/deadsnakes
  • sudo apt-get update
  • sudo apt-get install python2.6
  • sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 20
  • python --version should provide you 2.6.x. The weak module is not installed when the Python version is higher than 2.6.x.

After that, make sure your node and npm are the latest versions. I have node v0.10.28 and npm v1.4.9.

If you already have the phantom module installed, uninstall it by running npm uninstall phantom . Then run npm cache clean .

Now install weak separately: npm install weak . If this happens, install phantom by running npm install phantom .

This should solve the problem.

+3
source

I had the same problem and this code fixed my problem. Phantom version = 1.9.8 Phantom module version npm = 0.8.4

`

 var phantom=require('phantom'); phantom.create(function( ph ){ },{ dnodeOpts: { weak: false }, parameters:{ 'web-security': 'no' } }); 

`

0
source

All Articles