facebook/flow · error
flow-remove-types: the "checkPragma" option has been…
Error message
flow-remove-types: the "checkPragma" option has been replaced by "all".
What it means
Thrown by flow-remove-types' main transform function when the options object contains a `checkPragma` key. In v1.x, `checkPragma: false` told the tool to strip types from every file; v2.x removed that option and replaced it with the inverted `all` option (`all: true` transforms every file, otherwise only files with an @flow/@noflow pragma are processed). The check fires before any parsing, so nothing runs until the config is fixed.
Solutions
- Remove `checkPragma` from the options object entirely.
- If you relied on `checkPragma: false` (transform files without a pragma), switch to `all: true`.
- If you relied on `checkPragma: true` (default pragma detection), pass no option - that is the v2 default.
- Grep the repo for `checkPragma` to catch every transform/register entry point.
Example fix
// before
require('flow-remove-types/register')({checkPragma: false});
// after
require('flow-remove-types/register')({all: true}); Defensive patterns
Strategy: validation
Validate before calling
function sanitizeFlowRemoveTypesOptions(options) {
if (!options || !('checkPragma' in options)) return options;
const {checkPragma, ...rest} = options;
// v1 checkPragma:false meant transform everything -> v2 all:true
if (checkPragma === false) rest.all = true;
return rest;
}
// use
const out = flowRemoveTypes(source, sanitizeFlowRemoveTypesOptions(opts)); Prevention
- Grep for 'checkPragma' after every flow-remove-types major upgrade.
- Keep transform options in one shared module so there is a single place to migrate.
- Add a smoke test that calls the transform with your production options at startup.
When it happens
Trigger: Calling `require('flow-remove-types')(source, {checkPragma: ...})` (or flow-remove-types/register with the same options) with any value of checkPragma present, e.g. `{checkPragma: false}` left over from a 1.x setup; babel/jest configs that forward the whole options object.
Common situations: Upgrading flow-remove-types (or @babel dependencies that embed it) from 1.x to 2.x without updating build scripts; copied StackOverflow/codemod configs written for the old API; monorepos where one package was upgraded and its config is shared.
Related errors
- flow option must be "all" or "detect"
- flow-remove-types: includes and excludes must be RegExp or…
- sourceType option must be "script", "module", or…
- Attempted to insert a statement into
- Cannot insert array into non-array parent type
AI-assisted analysis of facebook/flow@f88ac94bcf (2026-08-20).
Data as JSON: /api/errors/1e8e9eef38d0906b.
Report an issue: GitHub.
Appendix: 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 f88ac94bcf)