```ts
/**
 * Parses KEY=VALUE pairs from a config string, ignoring blank lines,
 * comments (lines starting with #), and trims whitespace around keys
 * and values. Throws an error if a line has no = or an empty key.
 */
export function parseConfig(text: string): Record<string, string> {
  const config: Record<string, string> = {};
  const lines = text.split("\n");

  for (let i = 0; i < lines.length; i++) {
    let line = lines[i].trim();

    // Ignore blank lines and comments
    if (!line || line.startsWith("#")) continue;

    const equalsIndex = line.indexOf("=");
    if (equalsIndex === -1) {
      throw new Error(`Line ${i + 1} has no '='`);
    }

    const key = line.slice(0, equalsIndex).trim();
    const value = line.slice(equalsIndex + 1).trim();

    if (!key) {
      throw new Error(`Line ${i + 1} has an empty key`);
    }

    // Prevent prototype污染
    if (key === "__proto__") {
      Object.defineProperty(config, key, { value: value, writable: true, enumerable: true, configurable: true });
    } else {
      config[key] = value;
    }
  }

  return config;
}
```