Robigan 06
Robigan 06

Reputation: 33

Module Not Found for config.js

I keep getting this error that says

Error: Cannot find module './config.json'
Require stack:
- C:\Users\Sebas\source\repos\FunctionsLib\messages.js
- C:\Users\Sebas\source\repos\index.js

Now a little about my project, my project runs on Discordjs and am trying to make my project "modular", so I have my functions for chat management in another file, for example, a swear checker, the code of the swear checker is contained with another .js file called 'messages', and then is required in by the index.js which then, in turn, calls the functions, but also this messages.js file is requiring the index and the index is exposing variables so that the messages.js can read them. Right after I finished with this code. I kept getting the problem mentioned above, I restarted my PC thinking it was a problem with read and write perms. But I still get the problem, am 100% the location am mentioning for the config.json in both places is correct.

File structure:
C:.
│   .eslintrc.json
│   config.json
│   help.txt
│   index.js
│   package-lock.json
│   package.json
│   words.json
│
├───FunctionsLib
│       messages.js
│
├───Logs
(The rest is node_modules)

Here is a link to my source code https://drive.google.com/file/d/1z6cjPMZNWEQufbDn1ljNA5EdQNBFS698/view?usp=sharing

Upvotes: 1

Views: 973

Answers (1)

libik
libik

Reputation: 23049

Its the issue in messages.js which is inside of FunctionsLib directory.

To require files from higher directory you need to require it as '../config.json'

Upvotes: 1

Related Questions