diff --git a/esm.mjs b/esm.mjs index 0843cf349..1931c39cd 100644 --- a/esm.mjs +++ b/esm.mjs @@ -6,3 +6,13 @@ const require = createRequire(fileURLToPath(import.meta.url)); const esm = require('./dist/esm'); export const { resolve, load, getFormat, transformSource } = esm.registerAndCreateEsmHooks(); + +// Affordance for node 20, where load() happens in an isolated thread +export const globalPreload = () => { + const self = fileURLToPath(import.meta.url) + return ` +const { createRequire } = getBuiltin('module') +const require = createRequire(${JSON.stringify(self)}) +require('./dist/esm').registerAndCreateEsmHooks() +` +}