kamilrashid.dev
Menu

file_type_astro
Fixing __dirname is not defined in ES module scope error in NodeJS
Resolving '__dirname is not defined in ES module scope' error in NodeJS.
Jan 20, 2025

Fixing “__dirname is not defined in ES module scope” Error in NodeJS The solution is simple.

  • Declare const __dirname = import.meta.dirname; for __dirname
  • Declare const __basename = import.meta.dirname; for __basename