Cannot find module 'jade'

420 views
Skip to first unread message

Ryan Kreager

unread,
Aug 1, 2016, 4:48:04 PM8/1/16
to NodeChef
I'm experiencing a weird error. Trying to instantiate a basic app. Here's what I've got:

main.js:
require('./sites/app.js');


sites/app.js:
// Global app configuration section
app.set('view engine', 'jade'); // Set the template engine
app.set('views', './views'); // Specify the folder to find templates
console.log("App locals views (supra-app) = " + app.locals['views']);

require('./app/app.js')(app);
//var utils = require('./utils/app.js');

//app.use(mainApp);
//app.use('/utils', utils);

app.listen();


sites/app/app.js:
module.exports = function(app){
/* Lots more code here... */


When I try to load the root page at https://oneparish-dev-1222.nodechef.com, the middleware fires and I get a proper redirect and render. However, when I get to an app.render() call, I get this:

at Function.process_params (/bundle/node_modules/express/lib/router/index.js:410:3) 
at param (/bundle/node_modules/express/lib/router/index.js:365:14) 
at param (/bundle/node_modules/express/lib/router/index.js:349:14) 
at /bundle/node_modules/express/lib/router/index.js:277:22 
at Layer.handle [as handle_request] (/bundle/node_modules/express/lib/router/layer.js:95:5) 
at Route.dispatch (/bundle/node_modules/express/lib/router/route.js:112:3) 
at next (/bundle/node_modules/express/lib/router/route.js:131:13) 
at Layer.handle [as handle_request] (/bundle/node_modules/express/lib/router/layer.js:95:5) 
at /bundle/cloud/sites/app/app.js:62:13 
at ServerResponse.render (/bundle/node_modules/express/lib/response.js:960:7) 
at EventEmitter.render (/bundle/node_modules/express/lib/application.js:569:12) 
at new View (/bundle/node_modules/express/lib/view.js:78:30) 
at require (internal/module.js:12:17) 
at Module.require (module.js:354:17) 
at Function.Module._load (module.js:277:25) 
at Function.Module._resolveFilename (module.js:326:15) 
Error: Cannot find module 'jade' 
at next (/bundle/node_modules/express/lib/router/route.js:131:13) 
at Layer.handle [as handle_request] (/bundle/node_modules/express/lib/router/layer.js:97:5) 
at next (/bundle/node_modules/express/lib/router/route.js:121:14) 
at next (/bundle/node_modules/express/lib/router/index.js:271:10) 
at Function.process_params (/bundle/node_modules/express/lib/router/index.js:330:12) 
at /bundle/node_modules/express/lib/router/index.js:280:7 
at trim_prefix (/bundle/node_modules/express/lib/router/index.js:310:13) 
at Layer.handle_error (/bundle/node_modules/express/lib/router/layer.js:71:5) 
at /bundle/cloud/sites/app/app.js:57:13 
at ServerResponse.render (/bundle/node_modules/express/lib/response.js:960:7) 
at EventEmitter.render (/bundle/node_modules/express/lib/application.js:569:12) 
at new View (/bundle/node_modules/express/lib/view.js:78:30) 
at require (internal/module.js:12:17) 
at Module.require (module.js:354:17) 
at Function.Module._load (module.js:277:25) 
at Function.Module._resolveFilename (module.js:326:15) 
Error: Cannot find module 'jade'

I double-checked that jade is installed via npm.  Any assistance would be greatly appreciated!

dev.no...@gmail.com

unread,
Aug 1, 2016, 7:34:29 PM8/1/16
to NodeChef
Yeah correct is because the express module is not in your cloud folder. The way to fix this is under app actions > environment variables and then set 
variable name: NODE_PATH and variable value /bundle/cloud/node_modules

I have done this for your deployment. The reason for this is below is the folder structure of the parse server deployment

- cloud
  main.js
  -node_modules
     jade
index.js
- node_modules
  - express

Because the index.js initializes express, once you set the template engine to jade, there is no way the runtime will know jade is under cloud > node_modules unless you specifically set the NODE_PATH.

It will be easy to platform by default set the NODE_PATH once the container is started but i think it is best user controls this variable for now as some users could have local modules not in npm which they will want to expose globally as well. If we control the NODE_PATH variable they wont be able to do this.

But for now cannot find jade should be fixed.

dev.no...@gmail.com

unread,
Aug 1, 2016, 7:37:01 PM8/1/16
to NodeChef, dev.no...@gmail.com
I am updating our docs with this info as another user is most likely to face similar issue very soon when a different template engine is used.

dev.no...@gmail.com

unread,
Aug 1, 2016, 7:47:57 PM8/1/16
to NodeChef
Also the path to your views has to be an absolute path.

You can use the example provided in the nodechef parse server guide as in 

app.set('views', __dirname + '/views');

Note dirname is prefixed by a double underscore as in __dirname + '/views'

__dirname in node.js gives you the absolute path to the executing module.

dev.no...@gmail.com

unread,
Aug 1, 2016, 7:52:17 PM8/1/16
to NodeChef, dev.no...@gmail.com
In case you also want to explicitly set the view path as well, 

You can use. "/bundle/cloud/"

Note your app root is always /bundle. so /bundle/cloud ... and the rest of your structure follows.

Hope this helps.

Ryan Kreager

unread,
Aug 1, 2016, 11:28:22 PM8/1/16
to NodeChef, dev.no...@gmail.com
All your answers were helpful, but this one ended up being the best and most useful for our purposes. Thank you!
Reply all
Reply to author
Forward
0 new messages