【发布时间】:2019-11-23 18:23:54
【问题描述】:
我编写了这段代码,它使用 TypeScript 编写的很好。当我在赛普拉斯的测试文件中使用相同的代码时,我收到错误TypeError: fs.readdir is not a function
import * as fs from 'fs'
let inputPath: String = "C:\\Users\\rkon";
let replacementString = "/";
let newInputPath = inputPath.split('\\').join(replacementString)
console.log('path after replacement: ' + newInputPath);
fs.readdir(newInputPath as string, function (err: any, files: any[]) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
//listing all files using forEach
files.forEach(function (file) {
console.log('file: ' + file);
});
});
我首先验证了上面的代码:
>tsc temp.ts
>node temp.js
正如我所说,它运行良好,但为什么相同的代码在 Cypress 中不起作用,并出现以下错误:
TypeError: fs.readdir 不是函数
【问题讨论】:
-
看起来你可能需要修改你的模块分辨率标志。你在你的 node_modules 目录中也安装了 fs 吗?
标签: typescript cypress