facebook/flow · error · Error

flow-remove-types: the "checkPragma" option has been replace

Error message

flow-remove-types: the "checkPragma" option has been replaced by "all".

What it means

flow-remove-types renamed its checkPragma option to all: both control whether type stripping happens even when no @flow pragma is present. Because the old name would silently do nothing after the rename, the library now throws immediately when it sees checkPragma to force the migration. This is a deliberate API-break guard, not a runtime failure of the stripping logic.

Source

Thrown at packages/flow-remove-types/index.js:47

 *     COMPLIANT! Instead, use `declare foo: string;` for type-only fields.
 *
 *   - removeEmptyImports: (default: false)
 *     If true, removes empty import statements that remain after removing
 *     all type and typeof imports (e.g. `import {} from 'some-module'`).
 *
 * Returns an object with two methods:
 *
 *   - .toString()
 *     Returns the transformed source code.
 *
 *   - .generateMap()
 *     Returns a v3 source map.
 */
module.exports = function flowRemoveTypes(source, options) {
  // Options
  var all = Boolean(options && options.all);
  if (options && options.checkPragma) {
    throw new Error(
      'flow-remove-types: the "checkPragma" option has been replaced by "all".',
    );
  }

  // If there's no @flow or @noflow flag, then expect no annotation.
  var pragmaStart = source.indexOf('@' + 'flow');
  var pragmaSize = 5;
  if (pragmaStart === -1) {
    pragmaStart = source.indexOf('@' + 'noflow');
    pragmaSize = 7;
    if (pragmaStart === -1 && !all) {
      return resultPrinter(options, source);
    }
  }

  // This parse configuration is intended to be as permissive as possible.
  var ast = parse(source, {flow: all ? 'all' : 'detect', tokens: true});

View on GitHub (pinned to d1341dac89)

Solutions

  1. Replace every checkPragma: X with all: X in code and build config
  2. Search the repo and checked-in configs for 'checkPragma' to catch loader and register options
  3. Pin the pre-rename version only as a temporary stopgap while migrating

Example fix

// before
require('flow-remove-types')(src, {checkPragma: true});

// after
require('flow-remove-types')(src, {all: true});
Defensive patterns

Strategy: validation

Validate before calling

function normalizeOptions(options = {}) {
  if ('checkPragma' in options) {
    throw new Error('checkPragma was renamed to all; migrate options before calling');
  }
  return options;
}

Type guard

const hasMigratedOptions = (o) => o == null || !('checkPragma' in o);

Prevention

When it happens

Trigger: Calling require('flow-remove-types')(src, {checkPragma: true}) (or false) on any version after the rename; using an old config for the Node require hook, webpack or browserify loader, or CLI that still passes checkPragma.

Common situations: Upgrading flow-remove-types or the Flow toolchain in a repo whose build config (jest register hook, webpack loader options, gulp task) was written for the pre-rename API; copy-pasted snippets from old blog posts.

Related errors


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