【问题标题】:MongoDB - Error: Cannot find module '../build/Release/bson'MongoDB - 错误:找不到模块'../build/Release/bson'
【发布时间】:2015-03-24 01:42:03
【问题描述】:

我尝试以以下方式运行打字稿example,导致以下错误:

$ mongod --dbpath /home/u/databases
$ npm install
$ tsc --sourcemap --module commonjs app.ts
$ node app.js                             
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
========================================================================================
=  Please ensure that you set the default write concern for the database by setting    =
=   one of the options                                                                 =
=                                                                                      =
=     w: (value of > -1 or the string 'majority'), where < 1 means                     =
=        no write acknowledgement                                                       =
=     journal: true/false, wait for flush to journal before acknowledgement             =
=     fsync: true/false, wait for flush to file system before acknowledgement           =
=                                                                                      =
=  For backward compatibility safe is still supported and                              =
=   allows values of [true | false | {j:true} | {w:n, wtimeout:n} | {fsync:true}]      =
=   the default value is false which means the driver receives does not                =
=   return the information of the success/error of the insert/update/remove            =
=                                                                                      =
=   ex: new Db(new Server('localhost', 27017), {safe:false})                           =
=                                                                                      =
=   http://www.mongodb.org/display/DOCS/getLastError+Command                           =
=                                                                                      =
=  The default of no acknowledgement will change in the very near future                =
=                                                                                      =
=  This message will disappear when the default safe is set on the driver Db           =
========================================================================================

/home/u/tmp/TypeScriptSamples/imageboard/app.js:9
app.configure(function () {
    ^
TypeError: Object function (req, res, next) {
    app.handle(req, res, next);
  } has no method 'configure'
    at Object.<anonymous> (/home/u/tmp/TypeScriptSamples/imageboard/app.js:9:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:929:3

此外,查看 db.ts 我认为 package.json 文件中缺少 http 和 url,对吗?

如何使用 mongodb 修复上述错误?

【问题讨论】:

  • 在执行npm update之前有没有尝试过?

标签: javascript node.js mongodb typescript


【解决方案1】:

在 Linux 操作系统中,首先从 node_modules 中删除 bson 文件夹并运行以下命令:

sudo apt-get install gcc make build-essential 

然后重启nodejs文件如index.js。希望对你有帮助

【讨论】:

    【解决方案2】:

    我正在使用 connect-mongo 进行会话。我遇到了同样的问题,是因为 connect-mongo 的版本与 mongoose 的 4.0.x 版本产生了错误。您可以检查您正在使用的依赖项的每个版本。

    【讨论】:

      【解决方案3】:

      查看 db.ts 我认为 package.json 文件中缺少 http 和 url,对吗?

      没有。这些模块是核心 nodejs 的一部分。

      错误的来源是 package.json 在兼容版本锁中指定了最小数量而不向后。 https://github.com/Microsoft/TypeScriptSamples/blob/master/imageboard/package.json#L6 我会将 '>=' 更改为更难的版本,例如3.x

      【讨论】:

      • 谢谢,我删除了&gt;=,但是当我加载localhost:3000时出现了这个错误:TypeError: Property 'engine' of object #&lt;View&gt; is not a function at View.render (/home/u/tmp/TypeScriptSamples/imageboard/node_modules/express/lib/view.js:75:8) ...
      猜你喜欢
      • 2016-10-20
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 2016-08-19
      • 2016-10-05
      • 2013-01-24
      相关资源
      最近更新 更多