Cannot find module although the workspace shows the file

nodejs

#1

I am having an issue with my app.js

Which says: var eventRouter = require(’./src/routes/eventRoutes’);

My error is that : module.js:327

throw err;

^
Error: Cannot find module ‘./src/routes/eventRoutes’

However, under the project I have a src folder which houses the routes folder which the eventRoutes.ejs file.

I Cannot find what is causing this.

Can anyone help?


#2

Can you try removing the e from the file extension? .ejs stands for Embedded JavaScript, and is used by the EJS templating engine. .js is just a normal JavaScript file.


#3

I am using EJS with the Nodesjs and Express.
I’ll try the js and see if that works.
Thank you.


#4

I changed to js and reloaded, but this is what I get:
module.js:327
throw err;
^

Error: Cannot find module '.src/routes/eventRoutes’
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (/home/ubuntu/workspace/nodeproject/app.js:5:19)
at Module._compile (module.js:409:26)
at Object.Module._extensions…js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)

It worked when I only used views but messed up when I tried to break out the pages into routes.


#5

The error you’re showing has the path .src/routes/eventRoutes, can you add the missing slash to change it to this: ./src/routes/eventRoutes and try again


#6

Thank you. Yes, it is now working :blush: