oven-sh/bun · error · Error

sliceSourceCode truncated ${moduleList[i]} — likely a regex

Error message

sliceSourceCode truncated ${moduleList[i]} — likely a regex literal in a position builtin-parser.ts doesn't recognise. Leftover starts: ${processed.rest.slice(0, 80)}

What it means

Error "sliceSourceCode truncated ${moduleList[i]} — likely a regex literal in a position builtin-parser.ts doesn't recognise. Leftover starts: ${processed.rest.slice(0, 80)}" thrown in oven-sh/bun.

Source

Thrown at src/codegen/bundle-modules.ts:148

    }
    let importStatements: string[] = [];

    const processed = sliceSourceCode(
      "{" +
        input
          .replace(
            /\bimport(\s*type)?\s*(\{[^}]*\}|(\*\s*as)?\s[a-zA-Z0-9_$]+)\s*from\s*['"][^'"]+['"]/g,
            stmt => (importStatements.push(stmt), ""),
          )
          .replace(/export\s*{\s*}\s*;/g, ""),
      true,
      x => requireTransformer(x, moduleList[i]),
    );
    // Guard rail: builtin-parser.ts's regex-position heuristic only recognises
    // `/` as regex-start after `[(,=;:{]|return|=>`; a regex whose body has `)`
    // or `}` in any other position silently truncates. Fail loudly here.
    if (processed.rest.trim() !== "") {
      throw new Error(
        `sliceSourceCode truncated ${moduleList[i]} — likely a regex literal in a position builtin-parser.ts doesn't recognise. ` +
          `Leftover starts: ${processed.rest.slice(0, 80)}`,
      );
    }
    let fileToTranspile = `// GENERATED TEMP FILE - DO NOT EDIT
// Sourced from src/js/${moduleList[i]}
${importStatements.join("\n")}

${processed.result.slice(1).trim()}
;$$EXPORT$$(__intrinsic__exports).$$EXPORT_END$$;
`;

    // Attempt to optimize "$exports = ..." to a variableless return
    // otherwise, declare $exports so it works.
    let exportOptimization = false;
    fileToTranspile = fileToTranspile.replace(
      /__intrinsic__exports\s*=\s*(.*|.*\{[^\}]*}|.*\([^\)]*\))\n+\s*\$\$EXPORT\$\$\(__intrinsic__exports\).\$\$EXPORT_END\$\$;/,
      (_, a) => {

View on GitHub (pinned to 8c5296ac45)

When it happens

Trigger: Thrown at src/codegen/bundle-modules.ts:148 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/9928d4614dbc9e69. Report an issue: GitHub.