Cannot find Module *name*.js


I have a problem. I can execute everything, but when I try and type a command after the prefix “~”, it doesn’t recognize it. Like if I type “~help” in discord, it says in the error long cannot find “help.js” even though it’s there in the directory.

Error: Cannot find module ‘help.js’

Here is the corresponding code


I’d love some help as to why this is happening.


How are you referencing help.js from your main bot js file?


I had that typed before and it still wouldn’t call it and gave me the same error. That’s why I’m so confused over it.


May I see the directory structure?


Note that the CommonJS method (require) it uses fs.resolve to figure out where you’re importing a file from. When importing a module it should not start with ./ or ../ or / as those three tells CommonJS that you are importing a file from your project and not a module from node_modules directory.

When importing a file from current directory simply use:

const mod = require("./filename.extension");

However, if you’re importing a javascript file the extension isn’t needed:

const mod = require("./filename");

The way of loading the file above will be the same as:

const mod = require(__dirname + "/filename.js");

You can read more about how CommonJS work here