Skip to content

Commit 6b9daf0

Browse files
committed
loader: return empty globalPreload when not using off-thread loader
1 parent 6e1e66c commit 6b9daf0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

esm.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { fileURLToPath } from 'url';
22
import { createRequire } from 'module';
3+
import { versionGteLt } from './dist/util.js';
34
const require = createRequire(fileURLToPath(import.meta.url));
45

56
/** @type {import('./dist/esm')} */
67
const esm = require('./dist/esm');
78
export const { resolve, load, getFormat, transformSource } = esm.registerAndCreateEsmHooks();
89

910
// Affordance for node 20, where load() happens in an isolated thread
11+
const offThreadLoader = versionGteLt(process.versions.node, '20.0.0');
1012
export const globalPreload = () => {
13+
if (!offThreadLoader) {
14+
return '';
15+
}
1116
const self = fileURLToPath(import.meta.url);
1217
return `
1318
const { createRequire } = getBuiltin('module');

0 commit comments

Comments
 (0)