{"record":{"id":"39f14096c59faff2","repo":"windmill-labs/windmill","slug":"error-while-parsing-code-it-is-invalid-typescript-39f140","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/src/lib.rs","lineNumber":156,"sourceCode":"    tss.tsx = true;\n    tss.no_early_errors = true;\n    let lexer = Lexer::new(\n        Syntax::Typescript(tss),\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 expr = parser.parse_module().map_err(|e| {\n        anyhow::anyhow!(\"Error while parsing code, it is invalid TypeScript: {err_s}, {e:?}\")\n    })?;\n\n    let mut visitor = ImportsFinder { imports: HashSet::new(), skip_type_only };\n    visitor.visit_module(&expr);\n\n    let mut imports: Vec<_> = visitor.imports.into_iter().collect();\n    imports.sort();\n    Ok(imports)\n}\n\n/// Parse TypeScript/JavaScript code and extract relative imports resolved to absolute Windmill paths.\n///\n/// Takes the script's Windmill path (e.g., `\"f/folder/script\"`) and resolves relative imports\n/// like `\"./module\"` or `\"../utils\"` to absolute paths like `\"f/folder/module\"` or `\"f/utils\"`.\n///\n/// Only returns relative imports (those starting with `./`, `../`, or `/`).\n/// External package imports (e.g., `\"lodash\"`) are filtered out.\n///","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-ts/src/lib.rs#L138-L174","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the syntax error indicated in the wrapped SWC message","Check for merge-conflict markers (<<<<<<<) and unfilled placeholders","Validate the file with a TS compiler/linter before deploying","Ensure the content passed is complete TypeScript, not truncated"],"exampleFix":"// before\n<<<<<<< HEAD\nimport x from 'x';\n=======\nimport y from 'y';\n>>>>>>> branch\n// after\nimport x from 'x';","handlingStrategy":"try-catch","validationCode":"// pre-validate imports-bearing TS with the TS compiler\n// npx tsc --noEmit --allowJs false file.ts","typeGuard":null,"tryCatchPattern":"try {\n  parseTsImports(code);\n} catch (e) {\n  if (String(e).includes('invalid TypeScript')) {\n    // log the SWC diagnostic embedded in the message for the editor\n  } else throw e;\n}","preventionTips":["Lint scripts before deploy","Avoid exotic syntax not supported by the pinned SWC version","Ensure the code passed is whole TypeScript, not a fragment"],"tags":["typescript","swc","parser","imports","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"}