I am trying to test a node module before I publish it. However, when I npm install <path to module> and try requiring the module + running the main function, it throws this error:
Error: ENOENT: no such file or directory, scandir './data'
[90m at Object.readdirSync (node:fs:1044:3)[39m
at Object.<anonymous> (C:\Users\divinelemon\Downloads\Programming\Node.js\test-main\index.js:11:22)
[90m at Module._compile (node:internal/modules/cjs/loader:1108:14)[39m
[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)[39m
[90m at Module.load (node:internal/modules/cjs/loader:973:32)[39m
[90m at Function.Module._load (node:internal/modules/cjs/loader:813:14)[39m
[90m at Module.require (node:internal/modules/cjs/loader:997:19)[39m
[90m at require (node:internal/modules/cjs/helpers:92:18)[39m
at Object.<anonymous> (C:\Users\divinelemon\Downloads\Programming\Node.js\test\index.js:1:25)
[90m at Module._compile (node:internal/modules/cjs/loader:1108:14)[39m {
errno: [33m-4058[39m,
syscall: [32m'scandir'[39m,
code: [32m'ENOENT'[39m,
path: [32m'./data'[39m
}
However, this data folder exists, and I verified that the module worked when I ran a test in test-main (the module I'm trying to export).
I fixed this error by using this path instead of ./data:
./node_modules/random-usernames/data
But it seems pretty hacky, and I am unsure whether or not this is the correct way to fix this.
Help appreciated, Thanks