oven-sh/bun · error · SyntaxError

Could not parse directive value ${directive[2]} (must be JSO

Error message

Could not parse directive value ${directive[2]} (must be JSON parsable)

What it means

Error "Could not parse directive value ${directive[2]} (must be JSON parsable)" thrown in oven-sh/bun.

Source

Thrown at src/codegen/bundle-functions.ts:188

      const i = result.indexOf("{\n");
      // Support const enums in module scope.
      topLevelEnums.push({
        name: result.slice("const enum ".length, i).trim(),
        code: "\n" + result,
      });

      contents = rest;
    } else if (match[1] === "$") {
      const directive = contents.match(/^\$([a-zA-Z0-9]+)(?:\s*=\s*([^\r\n]+?))?\s*;?\r?\n/);
      if (!directive) {
        throw new SyntaxError("Could not parse directive:\n" + contents.slice(0, contents.indexOf("\n")));
      }
      const name = directive[1];
      let value;
      try {
        value = directive[2] ? JSON.parse(directive[2]) : true;
      } catch (error) {
        throw new SyntaxError("Could not parse directive value " + directive[2] + " (must be JSON parsable)");
      }
      if (name === "constructor") {
        directives.ConstructAbility = "CanConstruct";
      } else {
        directives[name] = value;
      }
      contents = contents.slice(directive[0].length);
    } else if (match[1] === "export function" || match[1] === "export async function") {
      // consume async token and function name
      const nameMatch = contents.match(/^export\s+(async\s+)?function\s([_a-zA-Z0-9]+)\s*/);
      if (!nameMatch)
        throw new SyntaxError("Could not parse function name:\n" + contents.slice(0, contents.indexOf("\n")));
      const async = Boolean(nameMatch[1]);
      const name = nameMatch[2];
      var remaining = contents.slice(nameMatch[0].length);

      // remove type parameters
      if (remaining.startsWith("<")) {

View on GitHub (pinned to 8c5296ac45)

When it happens

Trigger: Thrown at src/codegen/bundle-functions.ts:188 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/9835c18607671180. Report an issue: GitHub.