Registry / serialization / babel-plugin-transform-flow-enums

babel-plugin-transform-flow-enums

JSON →
library0.0.2jsnpmunverified

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.

npm install babel-plugin-transform-flow-enums
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-flow-enums
serializationjavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export (plugin function)
module.exports = require('babel-plugin-transform-flow-enums');
import plugin from 'babel-plugin-transform-flow-enums'; // Wrong: plugin is CommonJS, not ESM
This package is CommonJS-only without ESM support.
babel.config.js usage
plugins: ['babel-plugin-transform-flow-enums']
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
Options can be provided as the second element of an array in the plugin list.
getRuntime option
plugins: [['babel-plugin-transform-flow-enums', { getRuntime: (t) => t.memberExpression(t.identifier('require'), t.stringLiteral('flow-enums-runtime')) }]]
plugins: [['babel-plugin-transform-flow-enums', { getRuntime: 'flow-enums-runtime' }]] // Wrong: getRuntime must be a function, not a string
The getRuntime option receives Babel types (t) and must return a Babel AST node that references the runtime.

Set up Babel to transform Flow Enums using the required syntax plugin and runtime.

// Install dependencies: // npm install --save-dev babel-plugin-transform-flow-enums @babel/plugin-syntax-flow flow-enums-runtime // babel.config.js file: module.exports = { plugins: [ ['@babel/plugin-syntax-flow', { enums: true }], 'babel-plugin-transform-flow-enums' ] }; // Input file (test.js): // @flow enum Status { Active, Inactive } // After transform: // const Status = require('flow-enums-runtime').create(['Active', 'Inactive']);
Debug
Known issues
breakingFlow 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.
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.
affects: >=0.0.2
gotchaThe @babel/plugin-syntax-flow plugin must be configured with {enums: true} as the plugin option array, not as a top-level Babel option.
fix
Correct configuration: plugins: [['@babel/plugin-syntax-flow', { enums: true }]]
affects: >0.0.1
gotchaThe runtime dependency flow-enums-runtime must be installed in the project; this plugin will require it at runtime in the transformed code.
fix
Add flow-enums-runtime to your project dependencies: npm install flow-enums-runtime
affects: >=0.0.1
gotchaThis plugin only handles EnumDeclaration nodes; other flow enum-related syntax (e.g., enum member access) is left for the runtime.
fix
No fix needed; ensure flow-enums-runtime is used in your project.
affects: >=0.0.1
Errors
Common errors & fixes
SyntaxError: Support for the experimental syntax 'Flow' isn't currently enabled
Missing @babel/plugin-syntax-flow plugin.
fix
Add '@babel/plugin-syntax-flow' (with { enums: true } if using enums) to your Babel plugins.
Cannot find module 'flow-enums-runtime'
Missing runtime dependency in transformed code.
fix
Run 'npm install flow-enums-runtime' and ensure it's in your dependencies.
Error: [BABEL] unknown: .plugins[1][1] must be an object, false, or undefined (BCP 6)
Passing options as a string instead of an array or object.
fix
Use array form for plugin options: ['babel-plugin-transform-flow-enums', { getRuntime: ... }]
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
@babel/plugin-syntax-flowrequiredRequired for parsing Flow syntax including enums; must be enabled with {enums: true} configuration.
flow-enums-runtimerequiredRuntime dependency that this plugin generates calls to.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
babel-plugin-transform-flow-enums — npm install babel-plugin-transform-flow-enums · libregistry