Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 1c333aa

Browse files
fix: only use globalPreload for Node v20+ (#73)
1 parent b57bed7 commit 1c333aa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/loaders.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ type resolve = (
3434
recursiveCall?: boolean,
3535
) => MaybePromise<ResolveFnOutput>;
3636

37+
const isolatedLoader = compareNodeVersion([20, 0, 0]) >= 0;
38+
3739
/**
3840
* Technically globalPreload is deprecated so it should be in loaders-deprecated
3941
* but it shares a closure with the new load hook
4042
*/
4143
let mainThreadPort: MessagePort | undefined;
42-
export const globalPreload: GlobalPreloadHook = ({ port }) => {
44+
const _globalPreload: GlobalPreloadHook = ({ port }) => {
4345
mainThreadPort = port;
4446
return `
4547
const require = getBuiltin('module').createRequire("${import.meta.url}");
@@ -48,6 +50,8 @@ export const globalPreload: GlobalPreloadHook = ({ port }) => {
4850
`;
4951
};
5052

53+
export const globalPreload = isolatedLoader ? _globalPreload : undefined;
54+
5155
const extensions = ['.js', '.json', '.ts', '.tsx', '.jsx'] as const;
5256

5357
async function tryExtensions(

0 commit comments

Comments
 (0)