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
- Pass a literal boolean (`true`/`false`) for `useUnicodeFlag`.
- 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
- Never quote boolean values in JSON config.
- Use the shipped `Options` TypeScript interface to catch type errors at compile time.
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
- .babel property must be an object
- No config detected
- Config returned typeof ${typeof options}
- Expected config object but found array
- Negation of file paths is not supported.
AI-assisted analysis of babel/babel@06b6eae39d (2026-08-03).
Data as JSON: /data/errors/011254b5dc845c5f.json.
Report an issue: GitHub.