facebook/flow · error · Error

Failed to find extensionPath

Error message

Failed to find extensionPath

What it means

getExtensionPath() asks the VS Code API for the extension with the fixed ID 'flowtype.flow-for-vscode' and returns its install path. When vscode.extensions.getExtension returns undefined — the extension is not installed or enabled in this host — it throws 'Failed to find extensionPath'.

Source

Thrown at packages/flow-for-vscode/src/utils/getExtensionPath.ts:15

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import * as vscode from 'vscode';

const THIS_EXSTENSION_ID = 'flowtype.flow-for-vscode';

export default function getExtensionPath(): string {
  const thisExtension = vscode.extensions.getExtension(THIS_EXSTENSION_ID);
  if (!thisExtension) {
    throw new Error('Failed to find extensionPath');
  }
  return thisExtension.extensionPath;
}

View on GitHub (pinned to d1341dac89)

Solutions

  1. Mock `vscode.extensions.getExtension` in tests to return an object with extensionPath
  2. Ensure the extension is installed and enabled under the exact ID 'flowtype.flow-for-vscode'
  3. If you forked the extension, update THIS_EXSTENSION_ID in getExtensionPath.ts to your publisher ID

Example fix

// before (test)
import getExtensionPath from 'flow-for-vscode/src/utils/getExtensionPath';
getExtensionPath(); // throws: no real extension host

// after (test)
vi.mock('vscode', () => ({
  extensions: {
    getExtension: () => ({ extensionPath: '/fake/ext/path' }),
  },
}));
Defensive patterns

Strategy: type-guard

Validate before calling

import * as vscode from 'vscode';

function extensionPathAvailable(): boolean {
  return vscode.extensions.getExtension('flowtype.flow-for-vscode') != null;
}

Type guard

function getExtensionPathOrNull(): string | null {
  const ext = vscode.extensions.getExtension('flowtype.flow-for-vscode');
  return ext != null ? ext.extensionPath : null;
}

Prevention

When it happens

Trigger: Calling the extension's utils outside a real extension host (unit tests, running from source), the extension being installed under a different publisher ID, or the host not having the extension activated/enabled.

Common situations: Unit tests importing flow-for-vscode utils without mocking the vscode module; forks published under another publisher ID; the extension disabled for the workspace.

Related errors


AI-assisted analysis of facebook/flow@d1341dac89 (2026-08-17). Data as JSON: /api/errors/360e9187f8c4aedc. Report an issue: GitHub.