microsoft/typescript-go · critical · Error

Unable to resolve ${platformPackageName}. Either your platfo

Error message

Unable to resolve ${platformPackageName}. Either your platform is unsupported, or you are missing the package on disk.

What it means

Thrown by getExePath() when the package runs from an installed location (not repo source, not built npm output) and neither require.resolve nor import.meta.resolve can resolve @typescript/<name>-<platform>-<arch>/package.json. The platform binary ships as an optional dependency with os/cpu constraints; the throw means that dependency is absent on disk or does not exist for your platform.

Source

Thrown at _packages/native-preview/lib/getExePath.js:53

    else {
        // We're actually running from an installed package.
        const platformPackageName = "@typescript/" + expectedPackage;
        try {
            if (typeof import.meta.resolve === "undefined") {
                // v16.20.1
                const require = module.createRequire(import.meta.url);
                const packageJson = require.resolve(platformPackageName + "/package.json");
                exeDir = path.join(path.dirname(packageJson), "lib");
            }
            else {
                // v20.6.0, v18.19.0
                const packageJson = import.meta.resolve(platformPackageName + "/package.json");
                const packageJsonPath = fileURLToPath(packageJson);
                exeDir = path.join(path.dirname(packageJsonPath), "lib");
            }
        }
        catch (e) {
            throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk.");
        }
    }

    let exe = path.join(exeDir, binName);
    if (process.platform === "win32") {
        exe += ".exe";
        if (exe.length >= 248) {
            exe = "\\\\?\\" + exe;
        }
    }

    if (!fs.existsSync(exe)) {
        throw new Error("Executable not found: " + exe);
    }

    return exe;
}

View on GitHub (pinned to 1bcfa18d79)

Solutions

  1. Reinstall with optional dependencies included: npm install --include=optional (or drop --omit=optional) after removing node_modules
  2. Install the platform package explicitly: npm i @typescript/native-preview-<platform>-<arch> (e.g. -darwin-arm64, -linux-x64, -win32-x64)
  3. Verify your platform has a published prebuilt; if unsupported, there is no local workaround - use the JS TypeScript compiler instead
  4. Clear the package manager cache and reinstall if node_modules looks truncated
  5. Ensure Node >= 18.19 so import.meta.resolve exists (the fallback require.resolve path is Node 16 only)

Example fix

# before
npm install --omit=optional @typescript/native-preview

# after
npm install --include=optional @typescript/native-preview
# or pin the platform binary explicitly
npm i @typescript/native-preview-linux-x64
Defensive patterns

Strategy: validation

Validate before calling

// Verify the platform package is resolvable before calling getExePath()
const platformPkg = `@typescript/native-preview-${process.platform}-${process.arch}`;
let ok = false;
try { require.resolve(platformPkg + '/package.json'); ok = true; } catch {}
if (!ok) throw new Error(`${platformPkg} is not installed - install with --include=optional`);

Try / catch

try {
    exe = getExePath();
} catch (e) {
    if (e instanceof Error && e.message.includes('Unable to resolve')) {
        // actionable install fix: pull the platform package explicitly
        console.error(`npm i ${platformPkg} (or reinstall with --include=optional)`);
    } else throw e;
}

Prevention

When it happens

Trigger: npm/pnpm/yarn installed with optional dependencies skipped (--no-optional / --omit=optional / Node modules config) or the classic npm optional-deps bug; installing on an unsupported platform or architecture (no prebuilt package published); corrupted node_modules where the platform package directory is missing; Node older than 18.19/20.6 combined with a broken require context.

Common situations: CI images that strip optional deps to slim layers; Docker builds with --omit=optional; corporate proxies mangling installs; unusual arches (e.g., armv7, freebsd, 32-bit) with no tsgo prebuilt; pnpm hoisting layouts hiding the optional package.

Related errors


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/bea53cc91eb03124. Report an issue: GitHub.