TS1470
The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.
Broken Code ❌
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log(`Hello from directory: ${__dirname}`);Solution:
Since import.meta is not allowed when targeting CommonJS, you need to use an alternative method to determine the directory path. In a CommonJS environment, you can use the built-in __dirname global variable directly without needing to calculate it from __filename.
Fixed Code ✔️
import path from 'node:path';
console.log(`Hello from directory: ${__dirname}`);