{"id":19196,"library":"babel-plugin-transform-flow-enums","title":"babel-plugin-transform-flow-enums","description":"Transforms Flow Enum declarations (EnumDeclaration) into runtime calls using the flow-enums-runtime package. Current stable version is 0.0.2. Updated as part of Flow releases (e.g., v0.308.0 changed enum AST node shape). This plugin is essential for projects using Flow Enums and Babel, providing a compile-time transformation. Differentiators: official Facebook package, tightly coupled with Flow's enum syntax and runtime, supports boolean/number/string/symbol/bigint enum types. Requires @babel/plugin-syntax-flow with {enums: true} and the flow-enums-runtime package.","status":"active","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/facebook/flow","tags":["javascript"],"install":[{"cmd":"npm install babel-plugin-transform-flow-enums","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-flow-enums","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-flow-enums","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for parsing Flow syntax including enums; must be enabled with {enums: true} configuration.","package":"@babel/plugin-syntax-flow","optional":false},{"reason":"Runtime dependency that this plugin generates calls to.","package":"flow-enums-runtime","optional":false}],"imports":[{"note":"This package is CommonJS-only without ESM support.","wrong":"import plugin from 'babel-plugin-transform-flow-enums'; // Wrong: plugin is CommonJS, not ESM","symbol":"default export (plugin function)","correct":"module.exports = require('babel-plugin-transform-flow-enums');"},{"note":"Options can be provided as the second element of an array in the plugin list.","wrong":"plugins: [['babel-plugin-transform-flow-enums', { getRuntime: ... }]] // Wrong: passing options as array is correct only when options are provided; the string form without options is also valid","symbol":"babel.config.js usage","correct":"plugins: ['babel-plugin-transform-flow-enums']"},{"note":"The getRuntime option receives Babel types (t) and must return a Babel AST node that references the runtime.","wrong":"plugins: [['babel-plugin-transform-flow-enums', { getRuntime: 'flow-enums-runtime' }]] // Wrong: getRuntime must be a function, not a string","symbol":"getRuntime option","correct":"plugins: [['babel-plugin-transform-flow-enums', { getRuntime: (t) => t.memberExpression(t.identifier('require'), t.stringLiteral('flow-enums-runtime')) }]]"}],"quickstart":{"code":"// Install dependencies:\n// npm install --save-dev babel-plugin-transform-flow-enums @babel/plugin-syntax-flow flow-enums-runtime\n\n// babel.config.js file:\nmodule.exports = {\n  plugins: [\n    ['@babel/plugin-syntax-flow', { enums: true }],\n    'babel-plugin-transform-flow-enums'\n  ]\n};\n\n// Input file (test.js):\n// @flow\nenum Status { Active, Inactive }\n\n// After transform:\n// const Status = require('flow-enums-runtime').create(['Active', 'Inactive']);","lang":"javascript","description":"Set up Babel to transform Flow Enums using the required syntax plugin and runtime."},"warnings":[{"fix":"Update both plugin and Flow to compatible versions. If using Flow >=0.308.0, ensure babel-plugin-transform-flow-enums is updated to support new AST.","message":"Flow v0.308.0 changed the enum AST node structure from separate body types (EnumBooleanBody, etc.) to a single EnumBody node. Ensure your plugin version is compatible with your Flow version.","severity":"breaking","affected_versions":">=0.0.2"},{"fix":"Correct configuration: plugins: [['@babel/plugin-syntax-flow', { enums: true }]]","message":"The @babel/plugin-syntax-flow plugin must be configured with {enums: true} as the plugin option array, not as a top-level Babel option.","severity":"gotcha","affected_versions":">0.0.1"},{"fix":"Add flow-enums-runtime to your project dependencies: npm install flow-enums-runtime","message":"The runtime dependency flow-enums-runtime must be installed in the project; this plugin will require it at runtime in the transformed code.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"No fix needed; ensure flow-enums-runtime is used in your project.","message":"This plugin only handles EnumDeclaration nodes; other flow enum-related syntax (e.g., enum member access) is left for the runtime.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add '@babel/plugin-syntax-flow' (with { enums: true } if using enums) to your Babel plugins.","cause":"Missing @babel/plugin-syntax-flow plugin.","error":"SyntaxError: Support for the experimental syntax 'Flow' isn't currently enabled"},{"fix":"Run 'npm install flow-enums-runtime' and ensure it's in your dependencies.","cause":"Missing runtime dependency in transformed code.","error":"Cannot find module 'flow-enums-runtime'"},{"fix":"Use array form for plugin options: ['babel-plugin-transform-flow-enums', { getRuntime: ... }]","cause":"Passing options as a string instead of an array or object.","error":"Error: [BABEL] unknown: .plugins[1][1] must be an object, false, or undefined (BCP 6)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}