```ts

/** The KEY=VALUE pairs of a config file. */
export function parseConfig(text: string): Record<string, string> {
  const config: Record<string, string> = {};
  for (const line of text.split("\n")) {
    const trimmedLine = line.trim();
    if (trimmedLine === '' || trimmedLine.startsWith('#')) {
      continue;
    }
    const [key, value] = trimmedLine.split('=', 2);
    if (!key) {
      throw new Error(`Invalid config file: empty key found on line ${indexOfFirstChar(trimmedLine)}`);
    }
    if (!value) {
      throw new Error(`Invalid config file: no '=' sign found on line ${indexOfFirstChar(trimmedLine)}`);
    }
    config[key] = value.trim();
  }
  return config;
}

function indexOfFirstChar(s: string): number {
  for (let i = 0; i < s.length; i++) {
    const charCode = s.charCodeAt(i);
    if (!isWhitespace(charCode)) {
      return i + 1;
    }
  }
  return 1;
}

function isWhitespace(code: number): boolean {
  return [32, 9].includes(code); // Space and Tab
}
```