sinelaw/fresh · error

TypeScript parse errors

Error message

TypeScript parse errors: {}

What it means

`transpile_typescript` parses the given source with an oxc-based parser; if the parser reports any syntax errors the transpiler aborts with this message containing all parse errors joined by '; '. No JavaScript is produced until the source parses cleanly.

Solutions

  1. Read the joined error list in the message and fix each syntax error at the reported line/column in the .ts source.
  2. Pass a correct filename/extension (e.g. plugin.ts) so SourceType::from_path picks the right parser mode.
  3. Run tsc or a local parser on the source before submitting it to the bundler to catch errors early.

Example fix

// before
transpile_typescript(broken_src, "plugin.js")?; // parsed as JS, syntax errors
// after
transpile_typescript(broken_src, "plugin.ts")?; // parsed as TypeScript
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check with tsc or parse locally before transpiling
let ok = tsc_no_errors(path); // external or oxc pre-pass
if !ok { bail!("fix TypeScript syntax before bundling"); }

Try / catch

match transpile_typescript(src, "plugin.ts") {
    Err(e) if e.to_string().starts_with("TypeScript parse errors") => show_editor_diagnostics(&e.to_string()),
    other => other?,
}

Prevention

When it happens

Trigger: Passing TypeScript (or JS) source that is syntactically invalid to `transpile_typescript(source, filename)` — e.g. plugin bundles containing a typo, unbalanced braces, or unsupported syntax for the source type inferred from `filename`.

Common situations: Bundling a plugin whose .ts file has a syntax error; giving a filename whose extension makes oxc parse TS as plain JS (or vice versa); pasting partial/snippet code into a plugin loader.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/b2eeea3660804f88. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-parser-js/src/lib.rs:27

use oxc_codegen::Codegen;
use oxc_isolated_declarations::{IsolatedDeclarations, IsolatedDeclarationsOptions};
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
use oxc_transformer::{TransformOptions, Transformer};
use std::collections::HashSet;
use std::path::{Path, PathBuf};

/// Transpile TypeScript source code to JavaScript
pub fn transpile_typescript(source: &str, filename: &str) -> Result<String> {
    let allocator = Allocator::default();
    let source_type = SourceType::from_path(filename).unwrap_or_default();

    // Parse
    let parser_ret = Parser::new(&allocator, source, source_type).parse();
    if !parser_ret.errors.is_empty() {
        let errors: Vec<String> = parser_ret.errors.iter().map(|e| e.to_string()).collect();
        return Err(anyhow!("TypeScript parse errors: {}", errors.join("; ")));
    }

    let mut program = parser_ret.program;

    // Semantic analysis (required for transformer)
    let semantic_ret = SemanticBuilder::new().build(&program);

    if !semantic_ret.errors.is_empty() {
        let errors: Vec<String> = semantic_ret.errors.iter().map(|e| e.to_string()).collect();
        return Err(anyhow!("Semantic errors: {}", errors.join("; ")));
    }

    // Get scoping info for transformer
    let scoping = semantic_ret.semantic.into_scoping();

    // Transform (strip TypeScript types)
    let transform_options = TransformOptions::default();
    let transformer_ret = Transformer::new(&allocator, Path::new(filename), &transform_options)

View on GitHub (pinned to 67894ca546)