SeleniumHQ/selenium · error · Error

Unexpected compiled output format. Expected it to start with

Error message

Unexpected compiled output format. Expected it to start with "(function ", got: ${input.slice(0, 80)}

What it means

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.

Source

Thrown at javascript/atoms/typescript/wrap-as-global.js:60

// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.`;

const preamble = `
window.bot = window.bot || {};
window.bot.dom = window.bot.dom || {};
window.bot.dom.typescript = window.bot.dom.typescript || {};
window.bot.dom.typescript.IS_SHADOW_DOM_ENABLED = typeof ShadowRoot === 'function';
window.bot.dom.typescript.isShown = `;

const input = fs.readFileSync(inputPath, 'utf8');

// The compiled TypeScript output begins with "(function isShownElement(". Prepend the
// browser-global assignment so the atom is accessible as
// window.bot.dom.typescript.isShown in test pages.
if (!input.trimStart().startsWith('(function ')) {
  throw new Error(
    `Unexpected compiled output format. Expected it to start with "(function ", got: ${input.slice(0, 80)}`
  );
}

const output = licenseHeader + preamble + input.trimStart();
fs.writeFileSync(outputPath, output);

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Ensure the TypeScript compilation target/module settings produce an IIFE-style output starting with '(function '.
  2. Feed the correct compiled artifact (the plain JS IIFE, not a .ts source or sourcemap) as the input.
  3. 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.
  4. Diff the generated input against the last known-good output to see what envelope changed.

Example fix

// tsconfig before (emits ESM, breaks the guard)
{ "compilerOptions": { "module": "es2020", "target": "es2020" } }

// tsconfig after (emits IIFE-compatible output)
{ "compilerOptions": { "module": "none", "target": "es2018" } }
Defensive patterns

Strategy: validation

Validate before calling

const input = fs.readFileSync(inputPath, 'utf8')
if (!input.trimStart().startsWith('(function ')) {
  console.error('Compiled output does not start with (function ; check tsconfig module setting')
  process.exit(2)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/f29b801446ce3b30. Report an issue: GitHub.