TS1431
'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
Broken Code ❌
const inputStream = fs.createReadStream('file.csv');
const rl = readline.createInterface({
input: inputStream,
crlfDelay: Infinity,
});
for await (const line of rl) {
console.log(line);
}Fixed Code ✔️
Just add the imports for the fs module and readline module in order to turn your code into a module itself:
import fs from 'node:fs';
import readline from 'node:readline';
const inputStream = fs.createReadStream('file.csv');
const rl = readline.createInterface({
input: inputStream,
crlfDelay: Infinity,
});
for await (const line of rl) {
console.log(line);
}