我正在尝试让我的node / mongo / express应用程序在Openshift上运行。它在本地工作,但在Openshift上我得到一个错误:找不到模块('swig')我已将它添加到package.json中的依赖项中,如下所示。
"dependencies": {
"bcrypt-nodejs": "~0.0.3",
"consolidate": "~0.9.1",
"express": ">=3.x",
"mongodb": "~1.3.9",
"swig": "~0.14.0",
"validator": "~1.1.3"
},
"devDependencies": {},
"bundleDependencies": [],
我需要在我的server.js中这样:
var swig = require('swig'); var cons = require('consolidate');
//later app.engine('html', cons.swig);
完整错误读取:
Failed to load c++ bson extension, using pure JS version
Current directory: /var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/runtime/
repo
/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/runtime/repo/node_modules/m
ongodb/lib/mongodb/mongo_client.js:378
throw err
^
Error: failed to connect to [127.9.214.2:27017]
at null.<anonymous> (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/ru
ntime/repo/node_modules/mongodb/lib/mongodb/connection/server.js:553:74)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/ru
ntime/repo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15
)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/
runtime/repo/node_modules/mongodb/lib/mongodb/connection/connection.js:512:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:426:14
at process._tickCallback (node.js:415:13)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'
changed
Failed to load c++ bson extension, using pure JS version
Current directory: /var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/runtime/
repo
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Express server listening on port 8080
module.js:340
throw err;
^
Error: Cannot find module 'swig'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/
runtime/repo/server.js:3:12)
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)
DEBUG: Program node server.js exited with code 8
DEBUG: Starting child process with 'node server.js'
这是否是加载c ++ bson扩展失败的问题,导致这些其他错误?有没有解决这个问题的方法?它在本地工作正常,而不是在openshift。 在此先感谢您的帮助!
我重新安装了我的node-modules文件夹,删除它并运行npm install并修复了无法找到模块('swig')错误,但是,现在我收到一个错误,它无法找到模块'.. / helpers',它似乎是node-modules文件夹中swig内应存在的文件夹。我搜索了它被包含在哪里,这就是我得到的:
Searching 744 files for "../helpers"
C:\Repositories\meanapps\node_modules\swig\lib\tags\else.js:
1: var helpers = require('../helpers'),
2 _ = require('underscore');
3
C:\Repositories\meanapps\node_modules\swig\lib\tags\filter.js:
1: var helpers = require('../helpers'),
2 _ = require('underscore');
3
C:\Repositories\meanapps\node_modules\swig\lib\tags\for.js:
1: var helpers = require('../helpers'),
2 _ = require('underscore');
3
C:\Repositories\meanapps\node_modules\swig\lib\tags\if.js:
1: var helpers = require('../helpers'),
2 _ = require('underscore');
3
C:\Repositories\meanapps\node_modules\swig\lib\tags\import.js:
1: var helpers = require('../helpers'),
2 _ = require('underscore');
3
C:\Repositories\meanapps\node_modules\swig\lib\tags\include.js:
1: var helpers = require('../helpers'),
2 _ = require('underscore');
3
C:\Repositories\meanapps\node_modules\swig\lib\tags\set.js:
1: var helpers = require('../helpers'),
2 _ = require('underscore');
这可能是因为我使用了错误版本的swig吗?
好的,通过确保将它们通过git添加到openshift来修复该错误。现在,我得到了这个,我不知道它在寻找什么:
Error: ENOENT, no such file or directory '//layout.html'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.readFileSync (fs.js:284:15)
at getSingle (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/runtime/r
epo/node_modules/swig/lib/swig.js:152:19)
at get (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/runtime/repo/no
de_modules/swig/lib/swig.js:159:7)
at Object.exports.compileFile (/var/lib/openshift/52fda83ee0b8cd07040001cb/a
pp-root/runtime/repo/node_modules/swig/lib/swig.js:174:5)
at Object.<anonymous> (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/
runtime/repo/node_modules/swig/lib/parser.js:346:33)
at Array.forEach (native)
at Function._.each._.forEach (/var/lib/openshift/52fda83ee0b8cd07040001cb/ap
p-root/runtime/repo/node_modules/underscore/underscore.js:79:11)
at Object.precompile (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/r
untime/repo/node_modules/swig/lib/parser.js:324:7)
at Object.compile (/var/lib/openshift/52fda83ee0b8cd07040001cb/app-root/runt
ime/repo/node_modules/swig/lib/parser.js:425:18)
答案 0 :(得分:3)
我认为问题的第一部分是某种损坏的模块 - 可能是因为没有安装gcc,但可能没有。
我的建议是擦除你的节点模块,并使用npm缓存和重新获取模块:
rm -rf node_modules
npm cache clean
npm install
执行此操作后,您在打开文件'//layout.html'
时遇到问题这似乎是一个已知问题,由initializing swig and to tell it where to find the template解决。