【发布时间】:2016-08-02 14:43:02
【问题描述】:
背景信息
我正在尝试遵循本教程: http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/
我有一个运行在另一个 linux 机器上的 mongo 数据库......而且,我知道它正在工作,因为我有一个可以连接和查询的 php 应用程序。
我没有使用猫鼬...而是僧侣,因为这是教程所要求的。
这是我的 package.json 文件的样子:
{
"name": "testapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"mongodb": "^1.4.4",
"monk": "^1.0.1",
"morgan": "~1.6.1",
"pug": "^2.0.0-beta4",
"serve-favicon": "~2.3.0"
}
}
~
问题
当我尝试运行测试节点应用程序时,我收到以下错误消息:
me@mydevbox:/var/www/html/node/testapp$ node app.js
{ Error: Cannot find module '../build/Release/bson'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/www/html/node/testapp/node_modules/mongodb/node_modules/bson/ext/index.js:15:10)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3) code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
这是 index.js 文件的样子:
3 try {
4 // Load the precompiled win32 binary
5 if(process.platform == "win32" && process.arch == "x64") {
6 bson = require('./win32/x64/bson');
7 } else if(process.platform == "win32" && process.arch == "ia32") {
8 bson = require('./win32/ia32/bson');
9 } else {
10 bson = require('../build/Release/bson');
11 }
12 } catch(err) {
13 // Attempt to load the release bson version
14 try {
15 bson = require('../build/Release/bson');
16 } catch (err) {
17 console.dir(err)
18 console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
19 bson = require('../lib/bson/bson');
20 }
21 }
我的尝试:
根据 stackoverflow.com 上的其他帖子,我尝试将第 15 行更改为如下所示:
15 bson = require('bson');
我也试过运行命令:
sudo npm install bson
但这并没有解决问题。
如果有帮助,我在我的盒子上搜索了“bson”并得出了以下结果:http://pastebin.com/WKQygGak
系统信息
Ubuntu 15.10
编辑 1
me@mydevbox:/var/www/html/node/testapp$ sudo apt-get install gcc make build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version.
gcc is already the newest version.
make is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
然后我运行了以下命令:
第 10 行似乎有一个错误,但我不知道如何更正它。
编辑 2
这是我目前在我的 npm 配置中拥有的:
me@mydevbox:/var/www/html/node/testapp$ npm config list
; cli configs
user-agent = "npm/3.10.3 node/v6.3.1 linux x64"
; userconfig /home/me/.npmrc
https-proxy = "http://10.1.1.11:8080/"
proxy = "http://10.1.1.11:8080/"
python = "python2.7"
; globalconfig /usr/etc/npmrc
; node bin location = /usr/bin/nodejs
; cwd = /var/www/html/node/testapp
; HOME = /home/me
; "npm config ls -l" to show all defaults.
me@mydevbox:/var/www/html/node/testapp$
另外作为一个测试,我尝试“sudo npm install bson”,但它失败了,我在我发布的 pastebin 中看到了同样的错误。
【问题讨论】:
标签: javascript node.js mongodb bson monk