Node js and phantomjs - Cannot find module 'weak'
我正在64位Linux Mint 16上运行" petra",并且尝试与节点js一起首次使用" phantomjs"。
我已经在全球范围内安装了phantomjs:
1 | sudo npm install -g phantomjs |
...并确认它正在运行(我通过在终端中运行" phantomjs"得到phantomjs提示)
并且我已经在节点项目中安装了节点" phantom"模块:
1 | npm install phantom |
到现在为止还挺好。
但是,在我的应用程序代码中,它尝试执行此行时:
1 | var phantom = require('phantom'); |
...程序因以下跟踪信息而崩溃:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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) |
我可以确认确实在项目中的任何地方都没有" weak.js"。
我已经运行" npm install"以确保已安装所有依赖项。
Google搜索没有发现任何值得的东西。 谁能提供任何建议?
我在Windows机器上使用node.js和phantom时遇到了相同的问题,我发现您需要在Windows环境中进行一些特殊处理。 npm文件在这里。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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(function,options,callback),这里的选项使用dnodeOpts:{weak:false}
您是否在系统中安装了
您找到任何解决方案了吗?
编辑
而且,顺便说一下,我成功的系统与当前系统之间的关键区别在于,第一个是32位,而第二个是失败的是64位。是否模块"弱"有任何问题使其无法安装在64位盒上?
解决方案
通过执行以下步骤可以解决此问题:
之后,请确保您的节点和npm是最新版本。我有节点v0.10.28和npm v1.4.9。
如果您已经安装了幻影模块,请通过运行
现在,分别安装weak:
那应该解决问题。
我遇到了同样的问题,此代码解决了我的问题。
幻影版本= 1.9.8
Phantom npm模块版本= 0.8.4
`
1 2 3 4 5 6 7 8 9 10 | var phantom=require('phantom'); phantom.create(function( ph ){ },{ dnodeOpts: { weak: false }, parameters:{ 'web-security': 'no' } }); |
`