Skip to content

Commit 38c2dc5

Browse files
committed
This is a buffer here
1 parent 47f41a0 commit 38c2dc5

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lib/internal/modules/esm/get_format.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,13 @@ function underNodeModules(url) {
8484

8585
/**
8686
* Determine whether the given source contains CJS or ESM module syntax.
87-
* @param {string} source
87+
* @param {string | Buffer | undefined} source
8888
* @param {URL} url
8989
*/
9090
function detectModuleFormat(source, url) {
91-
try {
92-
return containsModuleSyntax(source, fileURLToPath(url), url) ? 'module' : 'commonjs';
93-
} catch {
94-
// containsModuleSyntax throws if source is undefined and the passed filename cannot be read
95-
// Return undefined so that the load hook can determine the format
96-
}
91+
const moduleSource = source ? `${source}` : undefined;
92+
const modulePath = fileURLToPath(url);
93+
return containsModuleSyntax(moduleSource, modulePath, url) ? 'module' : 'commonjs'
9794
}
9895

9996
let typelessPackageJsonFilesWarnedAbout;

0 commit comments

Comments
 (0)