diff --git a/npm/src/forge.ts b/npm/src/forge.ts index ae84d55787fa8..8bab943496ec3 100644 --- a/npm/src/forge.ts +++ b/npm/src/forge.ts @@ -9,14 +9,22 @@ const require = NodeModule.createRequire(import.meta.url) const __dirname = NodePath.dirname(fileURLToPath(import.meta.url)) function getBinaryPath() { + // Try to resolve the platform-specific binary path from the installed package + let resolvedPath: string | undefined try { - const binaryPath = require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`) - if (NodeFS.existsSync(binaryPath)) return binaryPath - } catch { - // Fall back to the binary written by postinstall into dist/ - return NodePath.join(__dirname, '..', 'dist', BINARY_NAME) - } + resolvedPath = require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`) + } catch {} + // Fallback to the binary written by postinstall into dist/ + const fallbackPath = NodePath.join(__dirname, '..', 'dist', BINARY_NAME) + + // Prefer the resolved package binary if it exists + if (resolvedPath && NodeFS.existsSync(resolvedPath)) return resolvedPath + + // Otherwise, use the postinstall fallback binary if present + if (NodeFS.existsSync(fallbackPath)) return fallbackPath + + // If neither binary exists, report a clear error and exit console.error(colors.red, `Platform-specific package ${PLATFORM_SPECIFIC_PACKAGE_NAME} not found.`) console.error(colors.yellow, 'This usually means the installation failed or your platform is not supported.') console.error(colors.reset)