[英]Node JS can't find module
I have a files.js
file and am requiring it at the start of my code.我有一个
files.js
文件,并且在我的代码开头需要它。
When I use:当我使用:
const files = require('./lib/files');
I get this error:我收到此错误:
Error: Cannot find module './lib/files'
错误:找不到模块“./lib/files”
However if I test it with another one of the files in the same folder like:但是,如果我使用同一文件夹中的另一个文件对其进行测试,例如:
const files = require('./lib/repo');
It runs.它运行。
files.js
: files.js
:
const fs = require('fs');
const path = require('path');
module.exports = {
getCurrentDirectoryBase: () => {
return path.basename(process.cwd());
},
directoryExists: (filePath) => {
return fs.existsSync(filePath);
}
};
I would use tree
command however I have too many node modules installed to show it correctly so:我会使用
tree
命令但是我安装了太多节点模块来正确显示它,所以:
const { getCurrentDirectoryBase, directoryExists } = require('./lib/files')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.