rollup/rollup · critical

not implemented: Cannot convert Decl::TsEnum

Error message

not implemented: Cannot convert Decl::TsEnum

What it means

The native Rust converter has no path for TypeScript `enum` declarations. Hitting `Decl::TsEnum` panics via `unimplemented!`. Unlike type-only constructs, enums have runtime values and need a real transform, which the native parser does not perform.

Source

Thrown at rust/parse_ast/src/convert_ast/converter.rs:282

    match declaration {
      Decl::Var(variable_declaration) => {
        self.store_variable_declaration(&VariableDeclaration::Var(variable_declaration))
      }
      Decl::Fn(function_declaration) => self.convert_function(
        &function_declaration.function,
        &TYPE_FUNCTION_DECLARATION,
        Some(&function_declaration.ident),
      ),
      Decl::Class(class_declaration) => self.store_class_declaration(
        class_declaration,
        outside_class_span_decorators_insert_position,
      ),
      Decl::Using(using_declaration) => {
        self.store_variable_declaration(&VariableDeclaration::Using(using_declaration))
      }
      Decl::TsInterface(_) => unimplemented!("Cannot convert Decl::TsInterface"),
      Decl::TsTypeAlias(_) => unimplemented!("Cannot convert Decl::TsTypeAlias"),
      Decl::TsEnum(_) => unimplemented!("Cannot convert Decl::TsEnum"),
      Decl::TsModule(_) => unimplemented!("Cannot convert Decl::TsModule"),
    }
  }

  fn convert_export_named_declaration(
    &mut self,
    export_named_declaration: &NamedExport,
    module_item_insert_position: &mut u32,
  ) {
    match export_named_declaration.specifiers.first() {
      Some(ExportSpecifier::Namespace(export_namespace_specifier)) => self
        .store_export_all_declaration(
          &export_named_declaration.span,
          export_named_declaration.src.as_ref().unwrap(),
          &export_named_declaration.with,
          Some(&export_namespace_specifier.name),
        ),
      None | Some(ExportSpecifier::Named(_)) => self.store_export_named_declaration(

View on GitHub (pinned to ddc4ffab62)

Solutions

  1. Add `@rollup/plugin-typescript` or `@rollup/plugin-swc` to transform enums before parsing.
  2. Replace enums with `const` objects (`const Color = { Red: 0, Green: 1 } as const`).
  3. Pre-compile `.ts` to `.js` and bundle the JS instead.

Example fix

// before
enum Color { Red, Green, Blue }

// after
const Color = { Red: 0, Green: 1, Blue: 2 } as const;
Defensive patterns

Strategy: fallback

Validate before calling

// Detect enum declarations before the native parser sees them.
const ENUM_RE = /\benum\s+\w+/;
function containsEnumDecl(code) {
  return ENUM_RE.test(code);
}

Try / catch

// Fall back to a TS transform plugin on enum panic.
try { await rollup(opts); }
catch (err) {
  if (/Cannot convert Decl::TsEnum/.test(err.message)) {
    opts.plugins = [swc({ ts: true }), ...(opts.plugins ?? [])];
    await rollup(opts);
  } else throw err;
}

Prevention

When it happens

Trigger: A `.ts` file containing `enum Color { Red, Green, Blue }` parsed natively by Rollup without a transpile plugin.

Common situations: Using enums in source fed directly to Rollup; assuming Rollup handles enums natively; large TS codebases that pervasively use enums.

Related errors


AI-assisted analysis of rollup/rollup@ddc4ffab62 (2026-08-03). Data as JSON: /data/errors/bce0038cb5731fbc.json. Report an issue: GitHub.