{"record":{"id":"3bf03a344fcf4092","repo":"windmill-labs/windmill","slug":"error-while-parsing-code-it-is-invalid-typescript","errorCode":null,"errorMessage":"Error while parsing code, it is invalid TypeScript: {err_s}, {e:?}","messagePattern":"Error while parsing code, it is invalid TypeScript: (.+?), (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-ts-asset/src/lib.rs","lineNumber":35,"sourceCode":"        // We want to parse ecmascript\n        Syntax::Typescript(TsSyntax::default()),\n        // EsVersion defaults to es5\n        Default::default(),\n        StringInput::from(&*fm),\n        None,\n    );\n\n    let mut parser = Parser::new_from(lexer);\n\n    let mut err_s = \"\".to_string();\n    for e in parser.take_errors() {\n        err_s += &e.into_kind().msg().to_string();\n    }\n\n    let ast = parser\n        .parse_module()\n        .map_err(|e| {\n            anyhow::anyhow!(\"Error while parsing code, it is invalid TypeScript: {err_s}, {e:?}\")\n        })?\n        .body;\n    let mut assets_finder =\n        AssetsFinder { assets: vec![], sql_queries: vec![], var_identifiers: HashMap::new() };\n    assets_finder.visit_module_items(&ast);\n    let pipeline = parse_pipeline_annotations(code);\n    Ok(ParseAssetsOutput::new(\n        merge_assets(assets_finder.assets),\n        assets_finder.sql_queries,\n        pipeline,\n    ))\n}\n\ntype VarAssetName = String;\ntype VarAssetSchema = Option<String>;\nstruct AssetsFinder {\n    assets: Vec<ParseAssetsResult>,\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-ts-asset/src/lib.rs#L17-L53","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Fix the TypeScript syntax error at the location listed in err_s / the SWC error detail","Check for unfilled template placeholders (`{{...}}`) and merge-conflict markers","Run the code through `tsc --noEmit` or an editor TS linter locally to see all syntax errors","Confirm the file is TypeScript and complete (not truncated)"],"exampleFix":"// before\nexport function main(a: number { return a; }\n// after\nexport function main(a: number) { return a; }","handlingStrategy":"try-catch","validationCode":"// client-side quick check before deploying\ntry { new Function(code); } catch { /* likely syntax error; run tsc for detail */ }\n// better: tsc --noEmit script.ts","typeGuard":null,"tryCatchPattern":"match parse_assets(code) {\n  Err(e) if e.to_string().contains(\"invalid TypeScript\") => {\n    // extract the SWC message from the error text and show a code-editor diagnostic\n  }\n  r => r?,\n}","preventionTips":["Run tsc --noEmit or an editor linter before saving/deploying","Strip merge-conflict markers and unfilled `{{...}}` placeholders","Deploy complete files, never partial edits"],"tags":["typescript","swc","parser","syntax-error"],"backgroundTag":"invalid-typescript-syntax","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}