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_expr_for_imports parses TypeScript with SWC to extract import statements (used by parse_relative_imports, parse_ts_imports, remove_pinned_imports). Invalid TypeScript makes SWC's parse_module fail, and this error surfaces the collected SWC diagnostics plus the failing error.

Source

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

    tss.tsx = true;
    tss.no_early_errors = true;
    let lexer = Lexer::new(
        Syntax::Typescript(tss),
        // 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 expr = parser.parse_module().map_err(|e| {
        anyhow::anyhow!("Error while parsing code, it is invalid TypeScript: {err_s}, {e:?}")
    })?;

    let mut visitor = ImportsFinder { imports: HashSet::new(), skip_type_only };
    visitor.visit_module(&expr);

    let mut imports: Vec<_> = visitor.imports.into_iter().collect();
    imports.sort();
    Ok(imports)
}

/// Parse TypeScript/JavaScript code and extract relative imports resolved to absolute Windmill paths.
///
/// Takes the script's Windmill path (e.g., `"f/folder/script"`) and resolves relative imports
/// like `"./module"` or `"../utils"` to absolute paths like `"f/folder/module"` or `"f/utils"`.
///
/// Only returns relative imports (those starting with `./`, `../`, or `/`).
/// External package imports (e.g., `"lodash"`) are filtered out.
///

View on GitHub (pinned to e474e8803c)

Solutions

  1. Fix the syntax error indicated in the wrapped SWC message
  2. Check for merge-conflict markers (<<<<<<<) and unfilled placeholders
  3. Validate the file with a TS compiler/linter before deploying
  4. Ensure the content passed is complete TypeScript, not truncated

Example fix

// before
<<<<<<< HEAD
import x from 'x';
=======
import y from 'y';
>>>>>>> branch
// after
import x from 'x';
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate imports-bearing TS with the TS compiler
// npx tsc --noEmit --allowJs false file.ts

Try / catch

try {
  parseTsImports(code);
} catch (e) {
  if (String(e).includes('invalid TypeScript')) {
    // log the SWC diagnostic embedded in the message for the editor
  } else throw e;
}

Prevention

When it happens

Trigger: parse_relative_imports or parse_ts_imports or remove_pinned_imports receiving code that SWC cannot parse — syntax errors, unbalanced tokens, or non-TS content — before the ImportsFinder visitor runs.

Common situations: Analyzing a script with a merge conflict, code containing raw template placeholders (`{{...}}` in windmill scripts is usually fine inside strings but breaks outside them), or truncated input during upload/deploy.

Related errors


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