{"record":{"id":"f29b801446ce3b30","repo":"SeleniumHQ/selenium","slug":"unexpected-compiled-output-format-expected-it-to","errorCode":null,"errorMessage":"Unexpected compiled output format. Expected it to start with \"(function \", got: ${input.slice(0, 80)}","messagePattern":"Unexpected compiled output format\\. Expected it to start with \"\\(function \", got: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/atoms/typescript/wrap-as-global.js","lineNumber":60,"sourceCode":"// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n// KIND, either express or implied.  See the License for the\n// specific language governing permissions and limitations\n// under the License.`;\n\nconst preamble = `\nwindow.bot = window.bot || {};\nwindow.bot.dom = window.bot.dom || {};\nwindow.bot.dom.typescript = window.bot.dom.typescript || {};\nwindow.bot.dom.typescript.IS_SHADOW_DOM_ENABLED = typeof ShadowRoot === 'function';\nwindow.bot.dom.typescript.isShown = `;\n\nconst input = fs.readFileSync(inputPath, 'utf8');\n\n// The compiled TypeScript output begins with \"(function isShownElement(\". Prepend the\n// browser-global assignment so the atom is accessible as\n// window.bot.dom.typescript.isShown in test pages.\nif (!input.trimStart().startsWith('(function ')) {\n  throw new Error(\n    `Unexpected compiled output format. Expected it to start with \"(function \", got: ${input.slice(0, 80)}`\n  );\n}\n\nconst output = licenseHeader + preamble + input.trimStart();\nfs.writeFileSync(outputPath, output);\n","sourceCodeStart":42,"sourceCodeEnd":67,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/atoms/typescript/wrap-as-global.js#L42-L67","documentation":"After successfully reading the compiled isShown TypeScript output, wrap-as-global.js asserts that the content begins with '(function ' (after trimStart). The compiled atom is expected to be an IIFE — `function isShownElement(...)` wrapped as `(function isShownElement(...)`. If the compiler emitted a different shape (ES module with import/export, an arrow function, a class, a bare statement, or a module-system wrapper like System.register), the prepend of `window.bot.dom.typescript.isShown =` would produce broken JavaScript, so the script fails fast. This is a build-integrity guard, not a runtime Selenium error.","triggerScenarios":"The tsc/babel configuration changed and now emits ES module syntax (export, import) instead of an IIFE. A module target bump (e.g. ES2020 with module: 'esnext') that changes the output envelope. The wrong file was fed as input (e.g. a source .ts or a sourcemap). A bundler pre-wrapped the output in define()/System.register. Manual editing of the compiled file removing the leading IIFE.","commonSituations":"Upgrading the TypeScript compiler or changing tsconfig module/_target settings in the atoms build. Pointing the wrap rule at the wrong tsc output artifact. A Bazel rule change that inserted an extra transform step altering the output envelope.","solutions":["Ensure the TypeScript compilation target/module settings produce an IIFE-style output starting with '(function '.","Feed the correct compiled artifact (the plain JS IIFE, not a .ts source or sourcemap) as the input.","If the compiler now emits ESM, add a bundler/format step (e.g. tsconfig module:'none' or a rollup iife wrapper) to restore the IIFE shape.","Diff the generated input against the last known-good output to see what envelope changed."],"exampleFix":"// tsconfig before (emits ESM, breaks the guard)\n{ \"compilerOptions\": { \"module\": \"es2020\", \"target\": \"es2020\" } }\n\n// tsconfig after (emits IIFE-compatible output)\n{ \"compilerOptions\": { \"module\": \"none\", \"target\": \"es2018\" } }","handlingStrategy":"validation","validationCode":"const input = fs.readFileSync(inputPath, 'utf8')\nif (!input.trimStart().startsWith('(function ')) {\n  console.error('Compiled output does not start with (function ; check tsconfig module setting')\n  process.exit(2)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the tsc module/target settings to emit an IIFE (module:'none').","Feed the correct compiled artifact, not source or sourcemap.","Re-run the compile step if the envelope changes after a compiler upgrade.","Diff generated input against last-known-good output."],"tags":["build","nodejs","bazel","atoms","typescript","compiler","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}