我试图从CasperJS内将记录插入到MongoDB集合中,但是首先遇到障碍。
我首先通过在应用程序的根目录中运行以下命令来安装mongodb:
npm install mongodb
这成功完成,没有任何错误。
我有一个名为server.js的CasperJS文件,其中包含以下行:
var db = require('mongodb');
当我尝试casperjs server.js
与此运行时,出现以下错误:
js-bson: Failed to load c++ bson extension, using pure JS version
Error: Cannot find module 'util'
/home/aaron/Documents/git/mateserver/phantomjs:/bootstrap.js:289
/home/aaron/Documents/git/mateserver/phantomjs:/bootstrap.js:254 in require
/home/aaron/Documents/git/mateserver/node_modules/mongodb/lib/mongodb/commands/insert_command.js:2
/home/aaron/Documents/git/mateserver/node_modules/mongodb/lib/mongodb/commands/insert_command.js:162
好像我缺少一个软件包,所以我运行命令:
npm install util
哪个运行成功,所以我尝试再次启动我的应用程序,但出现此错误:
js-bson: Failed to load c++ bson extension, using pure JS version
TypeError: 'undefined' is not a function (evaluating 'inherits(InsertCommand, BaseCommand)')
/home/aaron/Documents/git/mateserver/node_modules/mongodb/lib/mongodb/commands/insert_command.js:38
/home/aaron/Documents/git/mateserver/node_modules/mongodb/lib/mongodb/commands/insert_command.js:162
这就是我被困住的地方。我该如何解决?MongoDB与CasperJS不兼容吗?
我正在将CasperJS 1.1.0-beta3与MongoDB(通过npm安装)1.4.7一起使用。主机系统是Ubuntu 14.04 64位。
CasperJS在phantomjs上运行,它具有与node.js类似但不同的标准模块。您需要研究require
mongodb模块内部的所有'd模块,然后重写它们以使用phantomjs API而不是node.js API。您可能会遇到一些无法解决的问题。
对于该inherits
功能,似乎内部node.jsutil
模块存在周期性依赖关系,无法解决。您可以通过inherits.js
用inherits_browser.js
in覆盖解决此问题node_modules/util/node_modules/inherits
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句