{"record":{"id":"4adb0a8d524768e9","repo":"appsmithorg/appsmith","slug":"unable-to-generate-a-unique-accessor","errorCode":null,"errorMessage":"Unable to generate a unique accessor","messagePattern":"Unable to generate a unique accessor","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"app/client/src/workers/Evaluation/handlers/jsLibrary.ts","lineNumber":418,"sourceCode":"    return validVar;\n  }\n\n  let index = 0;\n\n  /**\n   * If the accessor is already taken, generate a unique name by appending an index to the accessor.\n   * The index is incremented until a unique name is found.\n   * 100 is a very large number and this loop should never run more than a few times.\n   */\n  while (index++ < 100) {\n    const name = `${validVar}_${index}`;\n\n    if (!takenAccessors.includes(name) && !takenNamesMap.hasOwnProperty(name)) {\n      return name;\n    }\n  }\n\n  throw new Error(\"Unable to generate a unique accessor\");\n}\n\n// TODO: Fix this the next time the file is edited\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function flattenModule(module: Record<string, any>) {\n  const keys = Object.keys(module);\n\n  // If there are no keys other than default, return default.\n  if (keys.length === 1 && keys[0] === \"default\") return module.default;\n\n  // If there are keys other than default, return a new object with all the keys\n  // and set its prototype of default export.\n  const libModule = Object.create(module.default || {});\n\n  for (const key of Object.keys(module)) {\n    if (key === \"default\") continue;\n\n    libModule[key] = module[key];","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/appsmithorg/appsmith/blob/8cd9021c24cdbea1c3c12c966073708e83db60c2/app/client/src/workers/Evaluation/handlers/jsLibrary.ts#L400-L436","documentation":"Thrown as a plain Error('Unable to generate a unique accessor') by generateUniqueAccessor. After deriving a validVar (the URL's filename with non-alphabetic chars replaced by '_' and trailing underscores stripped), the function tries validVar, then validVar_1 ... validVar_100 against takenAccessors and takenNamesMap. If all 101 candidates are taken, it gives up. In practice this is nearly unreachable: it requires 100+ libraries whose derived names collide to exactly the same validVar.","triggerScenarios":"Installing a very large number of libraries whose URLs all collapse to the same valid variable name (e.g. dozens of '+esm' URLs from the same package path, or many URLs whose only alphabetic residue is identical); an accessor namespace already saturated by data-tree entity names.","commonSituations":"Programmatic/bulk import of many similarly-named modules; a naming pattern (all-numeric or all-symbol URLs) that reduces to a near-empty validVar like '_'.","solutions":["Reduce the number of installed libraries that share the same derived name; remove duplicates.","Install from URLs whose path produces a distinct alphabetic name (distinct package/path segments).","If reproducing consistently, report it: the 100-cap is a safety ceiling, not expected behavior, and indicates a name-deriation collision worth fixing upstream."],"exampleFix":"// before (many libs collapse to the same accessor)\nhttps://cdn.jsdelivr.net/npm/x@1/+esm\nhttps://cdn.jsdelivr.net/npm/x@2/+esm\n... (100+ times)\n\n// after\nkeep only the one version actually used:\nhttps://cdn.jsdelivr.net/npm/x@2.0.0/+esm","handlingStrategy":"validation","validationCode":"// Before installing, ensure the derived accessor name is unique enough.\nfunction derivedAccessor(url) {\n  let name = url;\n  try { name = new URL(url).pathname.split('/').pop() ?? url; } catch {}\n  return name.replace(/[^a-zA-Z]/g, '_').replace(/_+$/, '');\n}\n// warn if many installed URLs collapse to the same derivedAccessor","typeGuard":"const isUniqueAccessor = (url, taken) => {\n  let name = url;\n  try { name = new URL(url).pathname.split('/').pop() ?? url; } catch {}\n  const v = name.replace(/[^a-zA-Z]/g, '_').replace(/_+$/, '');\n  return v && !taken.has(v);\n};","tryCatchPattern":"try {\n  await installLibrary(url);\n} catch (e) {\n  if (/unique accessor/i.test(e?.message ?? '')) {\n    showToast('Accessor collision. Remove duplicate libraries or pick a distinct URL.');\n  } else throw e;\n}","preventionTips":["Avoid installing dozens of libraries whose URLs collapse to the same name.","Keep only the versions you actually use; remove duplicate/superseded entries.","Prefer URLs whose pathname yields a distinct alphabetic name.","Report consistent reproduction: hitting the 100-cap indicates a real collision worth fixing upstream."],"tags":["js-library","evaluation","accessor","import"],"backgroundTag":null,"analyzedSha":"8cd9021c24cdbea1c3c12c966073708e83db60c2","analyzedAt":"2026-08-12T22:14:19.293Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}