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
wrap-get-attribute-as-global.js asserts the compiled getAttribute output starts with '(function (' (note the open paren after 'function', reflecting an anonymous-IIFE-with-params shape) before prepending window.bot.dom.typescript.getAttribute =. This differs slightly from the isShown/findElements wrapper, which checks '(function ' — the getAttribute compiled form uses an anonymous function with destructured/parenthesized params. Any other output envelope (ESM, named function, class, bare statement) fails fast to avoid emitting invalid JS.
Source
Thrown at javascript/atoms/typescript/wrap-get-attribute-as-global.js:59
// software distributed under the License is distributed on an
// "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.getAttribute = `;
const input = fs.readFileSync(inputPath, 'utf8');
// The compiled TypeScript output begins with "(function (". Prepend the
// browser-global assignment so the atom is accessible as
// window.bot.dom.typescript.getAttribute 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
- Ensure the getAttribute compile step emits output starting with '(function (' (anonymous IIFE).
- Feed the correct compiled getAttribute artifact as input.
- If the compiler now names the function, adjust the guard or the compile options to match the expected shape.
- Diff the input against the last-known-good output to see the signature change.
Example fix
// before (compiler emits named IIFE)
(function getAttribute(elem, name) { ... })
// after (anonymous IIFE matching the guard)
(function (elem, name) { ... }) Defensive patterns
Strategy: validation
Validate before calling
const input = fs.readFileSync(inputPath, 'utf8')
if (!input.trimStart().startsWith('(function (')) {
console.error('Compiled getAttribute output must start with (function (; check signature/module format')
process.exit(2)
} Prevention
- Ensure the compile step emits an anonymous IIFE '(function ('.
- Feed the correct compiled getAttribute artifact.
- Adjust compile options if function naming changes after an upgrade.
- Diff generated input against last-good output.
When it happens
Trigger: A tsconfig/module change causing getAttribute to compile to a named IIFE '(function getAttribute(' or ESM instead of '(function ('. Feeding the wrong compiled file. A transform step altering the function signature shape. Manual edits to the compiled output.
Common situations: TypeScript compiler upgrades that change emitted function naming (e.g. preserving the function name vs. anonymizing). Bazel rule pointing at the wrong artifact. Module format changes.
Related errors
- Unexpected compiled output format. Expected it to start with
- Unexpected compiled output format. Expected it to start with
- Expected input and output file paths
- Expected input and output file paths
- Expected input and output file paths
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/b1bd73eb70f3d7b6.
Report an issue: GitHub.