When converting a Node CommonJS module to an ES module, __dirname stops working.
Add this line to make it work again:
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
Starting Node 20.11 and 21.2, you can use
import.meta.dirnameinstead of__dirname.