Can’t find module ./commands/test but it exists


My Files

This is My Error
9:23 AM
internal/modules/cjs/loader.js:550
9:23 AM
throw err;
9:23 AM
^
9:23 AM
9:23 AM
Error: Cannot find module ‘./commands/test.js’
9:23 AM
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
9:23 AM
at Function.Module._load (internal/modules/cjs/loader.js:475:25)
9:23 AM
at Module.require (internal/modules/cjs/loader.js:598:17)
9:23 AM
at require (internal/modules/cjs/helpers.js:11:18)
9:23 AM
Jump Toat Object. (/app/bot/handler.js:10:18)
9:23 AM
at Module._compile (internal/modules/cjs/loader.js:654:30)
9:23 AM
at Object.Module._extensions…js (internal/modules/cjs/loader.js:665:10)
9:23 AM
at Module.load (internal/modules/cjs/loader.js:566:32)
9:23 AM
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
9:23 AM
at Function.Module._load (internal/modules/cjs/loader.js:498:3

I don’t know what is wrong because the file is definitely there.
Please help

Try removing the ./ and restart

Eg. commands/test.js

Im also going to assume this is a discord bot, moving this to #discord-help !

No, I still doesn’t work

It happened to me too a few weeks ago. I fixed it by doing this:

/app/data/config.js

Replace ./ with /app/.

From what I see, you did make a path error. For example if you’re in bot/handler.js and you want to require commands/test.js the path should be ./../commands/test.js.

That type of path is a relative path (path which starts with dot - .), when you are calling files from your current path in node.js the file you’re in.

Absloute path is when you accesing file from the top of your tree (like /). That type of path is working whatever the file you’re in. Just because it searches from the top of your tree instead of your current working location.

So, the absolute path for commands/test.js will be /commands/test.js

1 Like

Or you can add __dirname before referring to the file.

Try adding another .

../commands/test.js