user1640736 user1640736 - 1 month ago 5
Node.js Question

NodeJs : TypeError: require(...) is not a function

I am trying to require a file and afterwards pass it to a var. I am following this tutorial to create a authentication system. After writing the server.js file and trying to compile I got a bson error therefore I changed the line that required the release version of it in mongoose.

Here are my code and error :


require('./app/routes')(app, passport);


require('./app/routes')(app, passport);

TypeError: require(...) is not a function
at Object.<anonymous> (d:\Node JS learning\WorkWarV2\server.js:38:24)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3

Process finished with exit code 1

I have read that this usually means that requireJS is not getting loaded properly yet I am not aware why or how to fix it.

Edit due to comment:

As asked, here is the result of


I think this means that module.exports in your ./app/routes module is not assigned to be a function so therefore require('./app/routes') does not resolve to a function so therefore, you cannot call it as a function like this require('./app/routes')(app, passport).

Show us ./app/routes if you want us to comment further on that.