babel/babel · error · Error

.useUnicodeFlag must be a boolean, or undefined

Error message

.useUnicodeFlag must be a boolean, or undefined

What it means

@babel/plugin-transform-unicode-property-regex validates (index.ts:13) that `useUnicodeFlag` (default `true`) is a boolean. The value controls whether the generated regex gets the `u` flag; non-boolean values are rejected to prevent silent misuse such as the string `'false'` being truthy.

Source

Thrown at packages/babel-plugin-transform-unicode-property-regex/src/index.ts:14

/* eslint-disable @babel/development/plugin-name */
import { createRegExpFeaturePlugin } from "@babel/helper-create-regexp-features-plugin";
import { declare } from "@babel/helper-plugin-utils";

export interface Options {
  useUnicodeFlag?: boolean;
}

export default declare((api, options: Options) => {
  api.assertVersion(REQUIRED_VERSION("^7.0.0-0 || ^8.0.0"));

  const { useUnicodeFlag = true } = options;
  if (typeof useUnicodeFlag !== "boolean") {
    throw new Error(".useUnicodeFlag must be a boolean, or undefined");
  }

  return createRegExpFeaturePlugin({
    name: "transform-unicode-property-regex",
    feature: "unicodePropertyEscape",
    options: { useUnicodeFlag },
  });
});

View on GitHub (pinned to 06b6eae39d)

Solutions

  1. Pass a literal boolean (`true`/`false`) for `useUnicodeFlag`.
  2. Or omit the option entirely to accept the default `true`.

Example fix

// before
["@babel/plugin-transform-unicode-property-regex", { useUnicodeFlag: "true" }]
// after
["@babel/plugin-transform-unicode-property-regex", { useUnicodeFlag: true }]
Defensive patterns

Strategy: type-guard

Validate before calling

if (opts.useUnicodeFlag != null && typeof opts.useUnicodeFlag !== "boolean") {
  throw new TypeError("useUnicodeFlag must be a boolean");
}

Type guard

const isBoolOrUndef = v => v === undefined || typeof v === "boolean";

Prevention

When it happens

Trigger: Passing `useUnicodeFlag: "true"`, `useUnicodeFlag: 1`, `useUnicodeFlag: null`, or any other non-boolean value to the plugin.

Common situations: JSON/JSON5 config files where booleans get quoted; programmatic configs passing a number or an environment-variable string.

Related errors


AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03). Data as JSON: /data/errors/011254b5dc845c5f.json. Report an issue: GitHub.