windmill-labs/windmill · error

Error while parsing code, it is invalid TypeScript: {err_s},

Error message

Error while parsing code, it is invalid TypeScript: {err_s}, {e:?}

What it means

parse_assets uses the SWC parser to parse TypeScript code before walking the AST for asset annotations (asset blobs, SQL queries, variable references). When the code is not syntactically valid TypeScript, SWC's parse_module fails and this error wraps the accumulated SWC diagnostics plus the parser error.

Source

Thrown at backend/parsers/windmill-parser-ts-asset/src/lib.rs:35

        // We want to parse ecmascript
        Syntax::Typescript(TsSyntax::default()),
        // EsVersion defaults to es5
        Default::default(),
        StringInput::from(&*fm),
        None,
    );

    let mut parser = Parser::new_from(lexer);

    let mut err_s = "".to_string();
    for e in parser.take_errors() {
        err_s += &e.into_kind().msg().to_string();
    }

    let ast = parser
        .parse_module()
        .map_err(|e| {
            anyhow::anyhow!("Error while parsing code, it is invalid TypeScript: {err_s}, {e:?}")
        })?
        .body;
    let mut assets_finder =
        AssetsFinder { assets: vec![], sql_queries: vec![], var_identifiers: HashMap::new() };
    assets_finder.visit_module_items(&ast);
    let pipeline = parse_pipeline_annotations(code);
    Ok(ParseAssetsOutput::new(
        merge_assets(assets_finder.assets),
        assets_finder.sql_queries,
        pipeline,
    ))
}

type VarAssetName = String;
type VarAssetSchema = Option<String>;
struct AssetsFinder {
    assets: Vec<ParseAssetsResult>,

View on GitHub (pinned to e474e8803c)

Solutions

  1. Fix the TypeScript syntax error at the location listed in err_s / the SWC error detail
  2. Check for unfilled template placeholders (`{{...}}`) and merge-conflict markers
  3. Run the code through `tsc --noEmit` or an editor TS linter locally to see all syntax errors
  4. Confirm the file is TypeScript and complete (not truncated)

Example fix

// before
export function main(a: number { return a; }
// after
export function main(a: number) { return a; }
Defensive patterns

Strategy: try-catch

Validate before calling

// client-side quick check before deploying
try { new Function(code); } catch { /* likely syntax error; run tsc for detail */ }
// better: tsc --noEmit script.ts

Try / catch

match parse_assets(code) {
  Err(e) if e.to_string().contains("invalid TypeScript") => {
    // extract the SWC message from the error text and show a code-editor diagnostic
  }
  r => r?,
}

Prevention

When it happens

Trigger: Calling parse_assets on TS code with syntax errors: unbalanced braces/brackets, invalid syntax (e.g. `let let`), truncated files, or code written in another language (JSX mishandled, Python pasted in).

Common situations: Saving a script mid-edit, code generated by templates with unfilled placeholders like `{{ }}`, merge conflicts left in the file, or an asset-wrapped script where an interpolation broke the syntax.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/3bf03a344fcf4092. Report an issue: GitHub.