react/create-react-app · error · Error

Preset react-app: '${name}' option must be a boolean.

Error message

Preset react-app: '${name}' option must be a boolean.

What it means

babel-preset-react-app's create.js validates every option it accepts through validateBoolOption. If a passed option is defined but is not strictly of type 'boolean', the preset refuses to load. This is a hard guard: the preset only flips features on/off, so any non-boolean (string, number) is treated as a programmer error rather than coerced.

Source

Thrown at packages/babel-preset-react-app/create.js:17

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
'use strict';

const path = require('path');

const validateBoolOption = (name, value, defaultValue) => {
  if (typeof value === 'undefined') {
    value = defaultValue;
  }

  if (typeof value !== 'boolean') {
    throw new Error(`Preset react-app: '${name}' option must be a boolean.`);
  }

  return value;
};

module.exports = function (api, opts, env) {
  if (!opts) {
    opts = {};
  }

  var isEnvDevelopment = env === 'development';
  var isEnvProduction = env === 'production';
  var isEnvTest = env === 'test';

  var useESModules = validateBoolOption(
    'useESModules',
    opts.useESModules,
    isEnvDevelopment || isEnvProduction

View on GitHub (pinned to 6254386531)

Solutions

  1. Inspect the preset options object passed in your babel.config.js / .babelrc and ensure every value meant as a toggle is a real JavaScript boolean (true/false), not a string.
  2. If sourcing values from environment variables, coerce explicitly: Boolean(process.env.MY_FLAG) or process.env.MY_FLAG === 'true'.
  3. Remove the offending key entirely if you want the preset default (undefined is accepted and replaced with defaultValue).
  4. If forwarding options from a wrapper, filter/whitelist which keys you pass through to avoid leaking non-boolean values.

Example fix

// before
{
  presets: [['react-app', { development: process.env.NODE_ENV === 'development' ? 'yes' : 'no' }]]
}
// after
{
  presets: [['react-app', { development: process.env.NODE_ENV === 'development' }]]
}
Defensive patterns

Strategy: validation

Validate before calling

// Before invoking the preset, assert every toggle is boolean.
function sanitizePresetOpts(opts = {}) {
  const boolKeys = ['development', 'absoluteRuntime', 'runtime', 'flow', 'typescript'];
  const out = {};
  for (const k of Object.keys(opts)) {
    const v = opts[k];
    if (boolKeys.includes(k) && v !== undefined) {
      if (typeof v !== 'boolean') {
        throw new TypeError(`Option '${k}' must be boolean, got ${typeof v}`);
      }
      out[k] = v;
    } else {
      out[k] = v;
    }
  }
  return out;
}
// usage:
// presets: [['react-app', sanitizePresetOpts(myOpts)]]

Type guard

const isBoolOrUndefined = (v) => v === undefined || typeof v === 'boolean';
const hasValidBoolOpts = (opts) =>
  Object.values(opts || {}).every(isBoolOrUndefined);

Try / catch

try {
  require('babel-core').transform(code, {
    presets: [['react-app', opts]],
  });
} catch (e) {
  if (/option must be a boolean/.test(e.message)) {
    console.error('Preset option type error. Check non-boolean values in:', opts);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the preset with an options object where one of its boolean keys (e.g. development, absoluteRuntime, or any plugin toggle the preset forwards) holds a non-boolean value such as the string "true", the number 1, or null. The check is `typeof value !== 'boolean'` after defaulting undefined.

Common situations: Developers read NODE_ENV/BABEL_ENV from process.env and pass it directly into the preset options (strings leak in). Copy-pasting a config snippet that quotes booleans. Migrating from an older preset whose options accepted different types. Wrapping the preset in another preset that forwards options verbatim.

Related errors


AI-assisted analysis of react/create-react-app@6254386531 (2026-08-12). Data as JSON: /api/errors/6a602b9137399df2. Report an issue: GitHub.