{"record":{"id":"8e909f337bcf298f","repo":"karatelabs/karate","slug":"class-extends-value-is-not-a-constructor-or-null","errorCode":null,"errorMessage":"Class extends value is not a constructor or null","messagePattern":"Class extends value is not a constructor or null","errorType":"exception","errorClass":"JsErrorException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/Interpreter.java","lineNumber":1074,"sourceCode":"        }\n        // heritage: `extends <expr>` — the EXPR follows the EXTENDS token.\n        boolean hasExtends = false;\n        Object parentValue = null;\n        for (int i = 0, n = node.size(); i < n; i++) {\n            Node child = node.get(i);\n            if (child.token != null && child.token.type == EXTENDS) {\n                hasExtends = true;\n                parentValue = eval(node.get(i + 1), context);\n                break;\n            }\n        }\n        if (context.isError()) {\n            return Terms.UNDEFINED;\n        }\n        ObjectLike parentCtor = null;\n        if (hasExtends && parentValue != null && parentValue != Terms.UNDEFINED) {\n            if (!(parentValue instanceof JsCallable pc) || !pc.isConstructable() || !(parentValue instanceof ObjectLike)) {\n                throw JsErrorException.typeError(\"Class extends value is not a constructor or null\");\n            }\n            parentCtor = (ObjectLike) parentValue;\n        }\n        Node ctorFnExpr = null;\n        List<ClassMember> members = new ArrayList<>();\n        for (int i = 0, n = node.size(); i < n; i++) {\n            Node child = node.get(i);\n            if (child.type == NodeType.CLASS_STATIC_BLOCK) {\n                // rides the member list so it interleaves with the static field\n                // initializers in source order\n                ClassMember block = new ClassMember();\n                block.isStatic = true;\n                block.staticBlock = child;\n                members.add(block);\n                continue;\n            }\n            if (child.type != NodeType.CLASS_METHOD) {\n                continue; // CLASS / EXTENDS / name / heritage EXPR / braces / semicolons","sourceCodeStart":1056,"sourceCodeEnd":1092,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/Interpreter.java#L1056-L1092","documentation":"Thrown when a `class A extends B` has a non-null, non-undefined B that is not a constructable ObjectLike callable. Per spec, the extends value must be a constructor or null; primitives, plain values, or non-constructable callables are rejected at class-definition time.","triggerScenarios":"Evaluating `class A extends X` where X is a number, string, boolean, plain object, arrow function, or any non-constructable value. `class A extends undefined` is explicitly allowed.","commonSituations":"Import/order issues where the superclass variable is still a placeholder value; typos in class names; transpiled code inheriting from something that was a function in another engine but is not constructable here.","solutions":["Ensure the extends expression is a class (or regular function) defined before the derived class is evaluated.","If inheritance should be optional, use `extends null` explicitly rather than an undefined-resolving variable.","Log/inspect the extends value's type; primitives and plain objects cannot be extended."],"exampleFix":"// before\nvar base = { hello: 'world' };\nclass A extends base {}\n// after\nclass Base {}\nclass A extends Base {}","handlingStrategy":"validation","validationCode":"if (Parent !== null && Parent !== undefined && (typeof Parent !== 'function')) throw new Error('extends value must be a constructor or null');","typeGuard":"function isValidExtends(v) { return v === null || v === undefined || typeof v === 'function'; }","tryCatchPattern":"try { eval('class A extends ' + name + ' {}'); } catch (e) { /* falls back to default base class */ }","preventionTips":["Declare superclasses before derived classes","Never extend primitives or plain objects","Use `extends null` explicitly when intentionally baseless"],"tags":["javascript","class","extends"],"backgroundTag":"not-a-constructor","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}