Skip to content

Commit 4a18510

Browse files
committed
vfs: lazy-load esm/formats to fix shared library builds
The eager require of 'internal/modules/esm/formats' at module load time causes a TypeError in shared library builds where the module is not available. Make the require lazy since it's only needed when determining module format from file extension.
1 parent 7471a75 commit 4a18510

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/internal/vfs/module_hooks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
const path = require('path');
1515
const { dirname, extname, isAbsolute, resolve } = path;
1616
const pathPosix = path.posix;
17-
const { extensionFormatMap } = require('internal/modules/esm/formats');
17+
let extensionFormatMap;
1818

1919
/**
2020
* Normalizes a VFS path. Uses POSIX normalization for Unix-style paths (starting with /)
@@ -396,6 +396,9 @@ function getFormatFromExtension(filePath) {
396396
if (type === 'module') return 'module';
397397
return 'commonjs';
398398
}
399+
if (extensionFormatMap === undefined) {
400+
extensionFormatMap = require('internal/modules/esm/formats').extensionFormatMap;
401+
}
399402
return extensionFormatMap[ext] ?? 'commonjs';
400403
}
401404

0 commit comments

Comments
 (0)