我正在尝试在发布节点模块之前对其进行测试。但是,当我 npm install <path to module>
并尝试要求模块 + 运行主函数时,它会抛出此错误:
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
}
但是,此数据文件夹存在,并且我在 test-main
(我尝试导出的模块)中运行测试时验证了该模块是否正常工作。
我通过使用此路径而不是 ./data
修复了此错误:
./node_modules/random-usernames/data
但这似乎很棘手,我不确定这是否是解决此问题的正确方法。
感谢帮助, 谢谢