oven-sh/bun · error · Error

Require with dynamic specifier not supported here.

Error message

Require with dynamic specifier not supported here.

What it means

Thrown by sliceSourceCode in the builtin parser: it encountered a `require(...)` call in builtin JS source while a require transformer was installed, but the specifier is not a static string literal (it is a variable, template, or concatenation), so the regex /\brequire\(["']([^"']+)["']\)/ fails to match and the call cannot be rewritten at codegen time.

Solutions

  1. Use a static string literal as the require specifier so the parser can rewrite it
  2. Hoist the dynamic specifier resolution out of the builtin module and pass the result in as a parameter
  3. Extend replaceRequire handling to support template literals or concatenation if dynamic requires are genuinely needed
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/codegen/builtin-parser.ts:116 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/e686d9e89710cc61. Report an issue: GitHub.

Appendix: source

Thrown at src/codegen/builtin-parser.ts:116

        if (match) {
          contents = contents.slice(match[0].length);
          result += ")";
        } else {
          result += ",";
        }
        break;
      }
      i = 1;
    } else if (contents.startsWith("require(")) {
      if (replaceRequire) {
        const staticSpecifier = contents.match(/\brequire\(["']([^"']+)["']\)/);
        if (staticSpecifier) {
          const specifier = staticSpecifier[1];
          result += replaceRequire(specifier);
          contents = contents.slice(staticSpecifier[0].length);
          continue;
        } else {
          throw new Error("Require with dynamic specifier not supported here.");
        }
      } else {
        throw new Error("Require is not supported here.");
      }
    } else {
      console.error(contents.slice(0, 100));
      throw new Error("TODO");
    }
    result += contents.slice(0, i);
    contents = contents.slice(i);
  }

  return { result, rest: contents };
}

function sliceTemplateLiteralSourceCode(contents: string, replace: boolean) {
  let i = 0;
  let result = "";

View on GitHub (pinned to 8c5296ac45)