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

dependencies.js ships an identical validateBoolOption helper to create.js. The preset's dependencies entry-point validates its own boolean options the same way and rejects any defined option whose type is not boolean. The two files keep separate copies so the dependencies path can be required standalone.

Source

Thrown at packages/babel-preset-react-app/dependencies.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) {
  if (!opts) {
    opts = {};
  }

  // This is similar to how `env` works in Babel:
  // https://babeljs.io/docs/usage/babelrc/#env-option
  // We are not using `env` because it’s ignored in versions > babel-core@6.10.4:
  // https://github.com/babel/babel/issues/4539
  // https://github.com/facebook/create-react-app/issues/720
  // It’s also nice that we can enforce `NODE_ENV` being specified.
  var env = process.env.BABEL_ENV || process.env.NODE_ENV;
  var isEnvDevelopment = env === 'development';

View on GitHub (pinned to 6254386531)

Solutions

  1. Pass a dedicated, minimal options object to the dependencies entry containing only boolean-typed toggles.
  2. Coerce any env-sourced flag with Boolean(...) or an === 'true' comparison before handing it over.
  3. Drop keys you don't intend to override so the preset applies its defaults (undefined is allowed).
  4. Audit the shared config helper that builds options for both create.js and dependencies.js and split per-entry defaults.

Example fix

// before
const opts = { absoluteRuntime: process.env.ABS_RUNTIME, development: 'true' };
require('babel-preset-react-app/dependencies')(api, opts);
// after
const opts = { absoluteRuntime: Boolean(process.env.ABS_RUNTIME), development: true };
require('babel-preset-react-app/dependencies')(api, opts);
Defensive patterns

Strategy: validation

Validate before calling

// Build a dependencies-only options object with strict typing.
function buildDepsOpts(raw = {}) {
  const allowed = ['absoluteRuntime', 'development', 'runtime'];
  const out = {};
  for (const k of allowed) {
    if (raw[k] !== undefined) {
      if (typeof raw[k] !== 'boolean') {
        throw new TypeError(`dependencies opts: '${k}' must be boolean`);
      }
      out[k] = raw[k];
    }
  }
  return out;
}
require('babel-preset-react-app/dependencies')(api, buildDepsOpts(input));

Type guard

const isStrictBoolOpts = (o) =>
  Object.keys(o || {}).every((k) => typeof o[k] === 'boolean');

Try / catch

try {
  require('babel-preset-react-app/dependencies')(api, opts);
} catch (e) {
  if (/option must be a boolean/.test(e.message)) {
    console.error('Dependencies preset got a non-boolean option:', opts);
  }
  throw e;
}

Prevention

When it happens

Trigger: Requiring babel-preset-react-app/dependencies directly (e.g. for a dependencies-only Babel pass) with an options object containing a non-boolean value for one of its toggles. Same `typeof value !== 'boolean'` check after undefined is defaulted.

Common situations: Tooling that compiles package dependencies separately passes the same options block used for the main preset, which may include keys meaningful only to create.js or values typed as strings. Sharing one config object across both entry points.

Related errors


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