TS1103

'for await' loops are only allowed within async functions and at the top levels of modules.

Broken Code ❌

import fs from 'node:fs';
import readline from 'node:readline';
 
const inputStream = fs.createReadStream('file.csv');
 
function printLine(file: string): Promise<void> {
  const rl = readline.createInterface({
    input: inputStream,
    crlfDelay: Infinity,
  });
 
  for await (const line of rl) {
    console.log(line);
  }
}

Fixed Code ✔️

You have to mark your function with the async keyword:

import fs from 'node:fs';
import readline from 'node:readline';
 
const inputStream = fs.createReadStream('file.csv');
 
async function printLine(file: string): Promise<void> {
  const rl = readline.createInterface({
    input: inputStream,
    crlfDelay: Infinity,
  });
 
  for await (const line of rl) {
    console.log(line);
  }
}