appsmithorg/appsmith · error · TernDefinitionError
Failed to generate autocomplete definitions for ${name}.
Error message
Failed to generate autocomplete definitions for ${name}. What it means
Thrown as TernDefinitionError(name) after a library has installed successfully on self, while building autocomplete (Tern) definitions via makeTernDefs(self[key]) for each accessor. If makeTernDefs throws (e.g. the installed export is a structure the def-generator cannot walk, has circular references, or triggers an unexpected type), the accessors are rolled back (self[acc] = undefined) and the install is aborted with message 'Failed to generate autocomplete definitions for ${name}.'
Source
Thrown at app/client/src/workers/Evaluation/handlers/jsLibrary.ts:239
if (accessors.length === 0) {
throw new Error("Unable to determine a unique accessor");
}
// Name of the library is the last accessor. This is totally random and needs fixing.
const name = accessors[accessors.length - 1];
defs["!name"] = `LIB/${name}`;
try {
for (const key of accessors) {
defs[key] = makeTernDefs(self[key]);
}
} catch (e) {
for (const acc of accessors) {
self[acc] = undefined;
}
log.debug(e, `ternDefinitions failed for ${url}`);
throw new TernDefinitionError(
`Failed to generate autocomplete definitions: ${name}`,
);
}
// Restore the libraries from libStore to the global scope.
// This is done to ensure that the libraries are not overwritten by the newly installed library.
Object.keys(libStore).forEach((k) => (self[k] = libStore[k]));
//Reserve accessor names.
for (const acc of accessors) {
//we have to update invalidEntityIdentifiers as well
libraryReservedIdentifiers[acc] = true;
invalidEntityIdentifiers[acc] = true;
}
return { success: true, defs, accessor: accessors };
} catch (error) {
addTempStoredDataTreeToContext(tempDataTreeStore);View on GitHub (pinned to 8cd9021c24)
Solutions
- Try a different build of the same library (UMD vs ESM, or an earlier version) whose top-level export is a plain object/function.
- Pin to the last version that installed successfully if a recent release regressed.
- If only part of the library is needed, load a smaller subpath build that exposes a simpler export.
- Report the failing accessor/export shape so makeTernDefs can be hardened; the underlying thrown error is logged at debug level as 'ternDefinitions failed for ${url}'.
Example fix
// before https://cdn.jsdelivr.net/npm/heavylib@latest/dist/heavylib.full.js // circular export breaks makeTernDefs // after https://cdn.jsdelivr.net/npm/heavylib@2.3.0/dist/heavylib.core.js // simpler export shape
Defensive patterns
Strategy: fallback
Validate before calling
// No safe pre-check for makeTernDefs failure; validate the export shape is simple.
async function exportShape(url) {
const m = await import(/* webpackIgnore: true */ url).catch(() => null);
if (!m) return 'no-module';
try { JSON.stringify(m.default ?? m); return 'serializable'; }
catch { return 'cyclic-or-non-serializable'; }
} Type guard
const isPlainSerializable = (v, seen = new WeakSet()) => {
if (v === null || typeof v !== 'object') return true;
if (seen.has(v)) return false; // cycle
seen.add(v);
return Object.values(v).every(val => isPlainSerializable(val, seen));
}; Try / catch
try {
await installLibrary(url);
} catch (e) {
if (e?.name === 'TernDefinitionError') {
// Fallback: try an alternate build/version with a simpler export
await installLibrary(alternateUrlFor(url));
} else throw e;
} Prevention
- Prefer libraries with plain-object or function top-level exports.
- Pin to a known-good version; avoid @latest if a recent release regressed.
- Load a smaller subpath build when only part of a large library is needed.
- Watch the debug log line 'ternDefinitions failed for <url>' to identify the offender.
When it happens
Trigger: Installing a library whose top-level export contains deeply recursive, non-enumerable, or proxy/getter-heavy structures that break makeTernDefs; a build whose default export is a class instance with unusual prototype shape; an export whose typeof causes an unhandled branch in the def walker.
Common situations: Large frameworks (e.g. some ML/graph libs) with circular self-references; minified bundles that expose exotic object shapes; a library version whose entry export changed shape from a prior working version.
Related errors
- The script at ${url} cannot be installed.
- Unable to determine a unique accessor
- Unable to generate a unique accessor
- Failed to load JS libraries
- Found a Promise() during evaluation. Data fields cannot exec
AI-assisted analysis of appsmithorg/appsmith@8cd9021c24 (2026-08-12).
Data as JSON: /api/errors/da599adf6c5991f3.
Report an issue: GitHub.