{"record":{"id":"6d449530cfd221a8","repo":"grafana/k6","slug":"error-while-parsing-selector-selector-selec","errorCode":null,"errorMessage":"Error while parsing selector `${selector}` - selector cannot be empty","messagePattern":"Error while parsing selector `(.+?)` - selector cannot be empty","errorType":"exception","errorClass":"InvalidSelectorError","httpStatus":null,"severity":"critical","filePath":"internal/js/modules/k6/browser/common/js/injected_script.js","lineNumber":1141,"sourceCode":"    eat1();\n    if (operator !== \"=\" && typeof value !== \"string\")\n      throw new InvalidSelectorError(`Error while parsing selector \\`${selector}\\` - cannot use ${operator} in attribute with non-string matching value - ${value}`);\n    return { name: jsonPath.join(\".\"), jsonPath, op: operator, value, caseSensitive };\n  }\n  const result = {\n    name: \"\",\n    attributes: []\n  };\n  result.name = readIdentifier();\n  skipSpaces();\n  while (next() === \"[\") {\n    result.attributes.push(readAttribute());\n    skipSpaces();\n  }\n  if (!EOL)\n    syntaxError(void 0);\n  if (!result.name && !result.attributes.length)\n    throw new InvalidSelectorError(`Error while parsing selector \\`${selector}\\` - selector cannot be empty`);\n  return result;\n}\n\n// packages/injected/src/roleSelectorEngine.ts\nvar kSupportedAttributes = [\"selected\", \"checked\", \"pressed\", \"expanded\", \"level\", \"disabled\", \"name\", \"include-hidden\"];\nkSupportedAttributes.sort();\nfunction validateSupportedRole(attr, roles, role) {\n  if (!roles.includes(role))\n    throw new Error(`\"${attr}\" attribute is only supported for roles: ${roles.slice().sort().map((role2) => `\"${role2}\"`).join(\", \")}`);\n}\nfunction validateSupportedValues(attr, values) {\n  if (attr.op !== \"<truthy>\" && !values.includes(attr.value))\n    throw new Error(`\"${attr.name}\" must be one of ${values.map((v) => JSON.stringify(v)).join(\", \")}`);\n}\nfunction validateSupportedOp(attr, ops) {\n  if (!ops.includes(attr.op))\n    throw new Error(`\"${attr.name}\" does not support \"${attr.op}\" matcher`);\n}","sourceCodeStart":1123,"sourceCodeEnd":1159,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/js/injected_script.js#L1123-L1159","documentation":"An internal-invariant Go panic in cjsmodule.Evaluate (js/modules/cjsmodule.go:74). k6 compiles CommonJS sources only after the loader has wrapped them in a function body (the classic `function(exports, require, module, __filename, __dirname){...}` form), so rt.RunProgram must return a callable; sobek.AssertFunction failing means the wrapping/compilation pipeline produced something that is not a function. The message itself states this is a k6 bug, not a script-author error, and asks for a report — the panic is not a catchable JS exception.","triggerScenarios":"Requiring or importing a CommonJS module from a local file or npm-style dependency, where the wrapped program evaluates to a non-function due to a k6 loader defect (e.g. a change in how sources are wrapped, a sobek/goja upgrade, or an unusual module cache state). Nothing in a well-formed script can intentionally cause it.","commonSituations":"Hitting a regression in a specific k6 build while loading CommonJS npm dependencies via require(); running a forked or locally modified k6 where the CJS wrapper was altered; bisecting crashes after upgrading k6 or its JS runtime dependency. Essentially always accompanied by 'please report it' — users see it right at startup or at first require().","solutions":["Report it: open an issue at https://github.com/grafana/k6/issues with the script, the require'd module, and `k6 run --verbose` output","Reproduce with a minimal CommonJS file (module.exports = {}) to confirm it is not your script","Try a different k6 version — check the release notes for CJS/sobek loader fixes and upgrade or pin accordingly","Convert the affected module to an ES module (export/import) to bypass the cjsModule path entirely","If running a fork, verify any changes to the source-wrapping code in the loader"],"exampleFix":"// before (script.cjs-style dependency loaded through the CJS pipeline)\nconst lib = require('./legacy-lib.js'); // panics inside cjsmodule.Evaluate\n\n// after (bypass the CommonJS wrapper by using ESM)\nimport * as lib from './legacy-lib.mjs'; // requires converting the module to export/import","handlingStrategy":"fallback","validationCode":"null","typeGuard":null,"tryCatchPattern":"// This is a Go panic inside k6's module evaluation, not a JS exception;\n// try/catch in the script cannot intercept it. The only guards are\n// pre-run: pin a known-good k6 version and verify the CJS dependency loads:\n//   k6 run --verbose smoke-cjs.js   (smoke-cjs.js: const lib = require('./lib.js'); export default function() {})","preventionTips":["Prefer ES modules (import/export) over require() so the cjsModule wrapper path is never used","Pin the k6 version in CI after verifying CommonJS dependencies load","When upgrading k6, smoke-test scripts that require() local or npm CommonJS modules before rolling out","Report the panic with a minimal reproducer so the loader regression gets fixed upstream"],"tags":["commonjs","modules","require","internal-bug","panic","sobek"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}