{"record":{"id":"89ef9b5c1e3b1e74","repo":"SeleniumHQ/selenium","slug":"unexpected-compiled-output-format-expected-it-to-89ef9b","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-find-elements-as-global.js","lineNumber":56,"sourceCode":"//   http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing,\n// software distributed under the License is distributed on an\n// \"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.locators = window.bot.locators || {};\nwindow.bot.locators.typescript = window.bot.locators.typescript || {};\nwindow.bot.locators.typescript.findElements = `\n\nconst input = fs.readFileSync(inputPath, 'utf8')\n\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":38,"sourceCodeEnd":63,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/atoms/typescript/wrap-find-elements-as-global.js#L38-L63","documentation":"wrap-find-elements-as-global.js asserts the compiled findElements TypeScript output starts with '(function ' before prepending window.bot.locators.typescript.findElements =. If the compiler output a different envelope (ESM, class, System.register, bare statement), the assignment prepend would yield invalid JS, so it fails fast. Note: this script asserts the '(function ' prefix (without the trailing paren that getAttribute's wrapper checks), matching the isShown atom's output shape.","triggerScenarios":"A tsconfig/module change that emits ESM (export/import) instead of an IIFE. Feeding the wrong file (source, sourcemap, or a different atom's output). A bundler transform that wrapped the output in a module-system envelope. Manual edits stripping the leading IIFE.","commonSituations":"TypeScript/compiler upgrades altering the output module format. Bazel rule pointing the wrap step at the wrong compile artifact. Inserting an intermediate transform that changes the envelope.","solutions":["Ensure tsc emits an IIFE starting with '(function ' (module:'none' or equivalent).","Supply the correct compiled findElements artifact as input.","Add a format/bundle step if the compiler now emits ESM.","Diff input against last-good output to identify the envelope change."],"exampleFix":"// before (tsconfig emits ESM)\n{ \"compilerOptions\": { \"module\": \"es2020\" } }\n\n// after (IIFE-compatible)\n{ \"compilerOptions\": { \"module\": \"none\", \"target\": \"es2018\" } }","handlingStrategy":"validation","validationCode":"const input = fs.readFileSync(inputPath, 'utf8')\nif (!input.trimStart().startsWith('(function ')) {\n  console.error('Compiled findElements output does not start with (function ; check module format')\n  process.exit(2)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep tsc module settings producing IIFE output.","Point the wrap rule at the correct compile artifact.","Re-run compile after compiler upgrades.","Diff input against last-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"}