cannot find a module, root route not registering

27 views
Skip to first unread message

bryan rasmussen

unread,
May 13, 2014, 7:40:44 AM5/13/14
to compo...@googlegroups.com
Hi,

starting back up with compound after a long absence - and trying to get things to work..

I have the following in my application_controller.js
var utils = require("../helpers/utils.js");

utils.js exists inside of helpers folder.

When I navigate to any route I get

500 Error: Cannot find module '../helpers/utils.js'


However there is one route I cannot navigate to
In my config.js I have

exports.routes = function (map) {
   // Generic routes. Add all your routes below this line
    // feel free to remove generic routes
    map.get('/', 'root#index');

....

However when I go to localhost:3000 I get the default 'Welcome to Compound' view...

Thanks,
Bryan Rasmussen

bryan rasmussen

unread,
May 13, 2014, 6:35:30 PM5/13/14
to compo...@googlegroups.com
Ok I resolved the setting of the action for my root path, but I am still stuck with finding the module.

since var utils = require("../helpers/utils");
was returning

500 Error: Cannot find module '../helpers/utils.js'

I decided to try to do
console.log(require.resolve("application_controller.js"));
and I got back the same error, when I look at my terminal it says

Error in root controller
Error: Cannot find module 'application_controller.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.require.resolve (module.js:384:19)
    at eval (eval at <anonymous> (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/node_modules/kontroller/lib/base.js:157:17), <anonymous>:5:21)
    at eval (eval at <anonymous> (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/node_modules/kontroller/lib/base.js:157:17), <anonymous>:107:4)
    at Controller.BaseController.build (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/node_modules/kontroller/lib/base.js:158:9)
    at Controller.load (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/lib/controller-extensions.js:257:10)
    at eval (eval at <anonymous> (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/node_modules/kontroller/lib/base.js:157:17), <anonymous>:2:33)
    at eval (eval at <anonymous> (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/node_modules/kontroller/lib/base.js:157:17), <anonymous>:86:4)
    at Controller.BaseController.build (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/node_modules/kontroller/lib/base.js:158:9)
    at ControllerBridge.getInstance (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/lib/controller-bridge.js:257:13)
    at ControllerBridge.loadController (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/lib/controller-bridge.js:193:21)
    at ControllerBridge.callControllerAction (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/lib/controller-bridge.js:155:20)
    at ControllerBridge.<anonymous> (/Users/bryan/PROTO/tryingout/copycat/node_modules/compound/lib/controller-bridge.js:149:14)
    at callbacks (/Users/bryan/PROTO/tryingout/copycat/node_modules/express/lib/router/index.js:164:37)
    at param (/Users/bryan/PROTO/tryingout/copycat/node_modules/express/lib/router/index.js:138:11)
    at pass (/Users/bryan/PROTO/tryingout/copycat/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (/Users/bryan/PROTO/tryingout/copycat/node_modules/express/lib/router/index.js:173:5)
    at Object.router (/Users/bryan/PROTO/tryingout/copycat/node_modules/express/lib/router/index.js:33:10)
    at next (/Users/bryan/PROTO/tryingout/copycat/node_modules/express/node_modules/connect/lib/proto.js:193:15)
    at Object.methodOverride [as handle] (/Users/bryan/PROTO/tryingout/copycat/node_modules/express/node_modules/connect/node_modules/method-override/index.js:48:5)
    at next (/Users/bryan/PROTO/tryingout/copycat/node_modules/express/node_modules/connect/lib/proto.js:193:15)
    at /Users/bryan/PROTO/tryingout/copycat/node_modules/express/node_modules/connect/node_modules/express-session/index.js:225:9
    at /Users/bryan/PROTO/tryingout/copycat/node_modules/express/node_modules/connect/node_modules/express-session/session/memory.js:50:9
    at process._tickCallback (node.js:415:13)

Now the thing is - the require.resolve that is raising the error is happening inside of application_controller.js, which means that require cannot resolve application_controller.js from within application_controller.js, it cannot resolve ../helpers/utils.js

So I do the following
var utils = require(require('path').dirname(require.main.filename) + "/app/helpers/utils");

and that works, but really should I have to do this? Is it a bug? Is there something else I am doing wrong?

Ion Caliman

unread,
Jul 19, 2014, 5:01:10 AM7/19/14
to compo...@googlegroups.com
You must require './app/helpers/utils'
I don't now why, but this will work :)
Reply all
Reply to author
Forward
0 new messages