Skip to content

detect null and undefined loader-returned sources

Compare
Choose a tag to compare
@iambumblehead iambumblehead released this 07 Sep 19:29
2fc016c

Detects null AND undefined loader-returned source definitions

diff --git a/src/esmockLoader.js b/src/esmockLoader.js
index 69dedd4..e835ec3 100644
--- a/src/esmockLoader.js
+++ b/src/esmockLoader.js
@@ -145,7 +145,8 @@ const load = async (url, context, nextLoad) => {
       if (!/^(commonjs|module)$/.test(nextLoadRes.format))
         return nextLoad(url, context)
 
-      const source = nextLoadRes.source === null
+      // nextLoadRes.source sometimes 'undefined' and other times 'null' :(
+      const source = nextLoadRes.source === null || nextLoadRes.source === undefined
         ? String(await fs.readFile(new URL(url)))
         : String(nextLoadRes.source)
       const hbang = (source.match(hashbangRe) || [])[0] || ''