문제

I am trying to get my node/mongo/express app working on Openshift. It works locally, but on Openshift I am getting an Error: Cannot find module ('swig') I have added it to my dependencies in the package.json as shown below.

"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": [],

And I require it in my server.js like so:

var swig = require('swig'); var cons = require('consolidate'); 
//later app.engine('html', cons.swig);

The Full Error reads:

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'

Is this a problem with the Failure to load c++ bson extension, that is causing these other errors? Is there a way around this problem? It works fine locally, just not on openshift. Thanks in advance for your help!


I re-installed my node-modules folder by deleting it and running npm install and that fixed the Cannot find module ('swig') Error, however, now I am getting an error that it cannot find the module '../helpers', which seems to be a folder that should exist inside of swig within the node-modules folder. I ran a search for where it is being included and this is what I got:

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');

Could this be because I am using an incorrect version of swig?

Ok, fixed that error by making sure they were added through git to openshift. Now, I get this and I have no idea what it is looking for:

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)
도움이 되었습니까?

해결책

I think the first part of your problem is some sort of corrupted module - perhaps due to gcc not being installed, but maybe not.

My suggestion is to wipe your node modules, and npm cache and re-acquire the modules using:

rm -rf node_modules
npm cache clean
npm install

Once you did this, you experienced problems opening a file '//layout.html'

This seems to be a known problem, resolved by initializing swig and to tell it where to find the template.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top