【发布时间】:2019-10-29 19:54:41
【问题描述】:
这是一个非常简单的,我希望从 js 中工作:
import * as fs from 'fs';
var testDir = './tests';
// Add each .js file to the mocha instance
fs.readdirSync(testDir)
.filter(function(file) {
// Only keep the .js files
return file.substr(-3) === '.js';
})
.forEach(function(file) {
mochaInstance.addFile(path.join(testDir, file));
});
我正在运行此代码的转译版本,但这会引发错误:
错误:ENOENT:没有这样的文件或目录,scandir './tests' 在 Object.readdirSync (fs.js:783:3)
我该如何解决这个问题?我确定文件 './tests' 的目录是正确的,我的节点版本是 v10.13.0
【问题讨论】:
-
标准函数不知道相对路径,建议使用
__dirname + '/tests',否则可以使用path -
你只是在编译吗?还是你也在包装?您的任何代码是否与当前目录混淆,因为
./是相对于当前工作目录的。