diff --git a/lib/internal/modules/esm/initialize_import_meta.js b/lib/internal/modules/esm/initialize_import_meta.js index f1ca32209d9521..8705f4175c463a 100644 --- a/lib/internal/modules/esm/initialize_import_meta.js +++ b/lib/internal/modules/esm/initialize_import_meta.js @@ -67,20 +67,10 @@ function resolveModuleMeta(url) { return { __dirname: undefined, __filename: undefined }; } - // We return an object with getters to reduce memory usage in modules that - // do not use these properties, i.e. most modules don't need the values - // to be resolved until the first time the property is accessed. - let filePath; - let dirPath; + const filePath = fileURLToPath(url); return { - get __dirname() { - return dirname(filePath ??= fileURLToPath(url)); - }, - get __filename() { - filePath ??= fileURLToPath(url); - dirPath ??= dirname(filePath); - return filePath; - }, + __dirname: dirname(filePath), + __filename: filePath, }; }