Skip to content

Commit 7fda745

Browse files
fix(sdk/native): load platform binding under pnpm
1 parent 390581c commit 7fda745

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

‎sdk/native/src/nativeBinding.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -598,16 +598,15 @@ function tryRequireNativeBinding(requireFn: NodeJS.Require, candidate: string):
598598
}
599599

600600
function resolveRequire() {
601-
const globalRequire = (globalThis as typeof globalThis & { require?: NodeJS.Require }).require;
602-
if (typeof globalRequire === "function") {
603-
return globalRequire;
604-
}
605-
601+
// Always prefer a require anchored to this package, not a global/root require.
602+
// In pnpm workspace layouts, relying on the process CWD can make optional
603+
// platform packages (e.g. @codex-native/sdk-darwin-arm64) unreachable from
604+
// the main package.
606605
if (typeof __filename === "string") {
607606
try {
608607
return createRequire(__filename);
609608
} catch {
610-
// fall through to other strategies
609+
// fall through
611610
}
612611
}
613612

@@ -616,10 +615,12 @@ function resolveRequire() {
616615
try {
617616
return createRequire(importMetaUrl);
618617
} catch {
619-
// fall through to fallback strategy
618+
// fall through
620619
}
621620
}
622621

622+
// Final fallback: still create a stable require, but avoid globalThis.require
623+
// and prefer a package-adjacent path.
623624
const fallbackBase = typeof __dirname === "string" ? __dirname : process.cwd();
624625
const fallbackPath = path.join(fallbackBase, "noop.js");
625626
return createRequire(fallbackPath);

0 commit comments

Comments
 (0)