Get this error in Node v14.16.0 when doing insert operation using objection@v2.2.15 when ajv@8 is locked (by other dependencies):
TypeError: Class constructor Ajv cannot be invoked without 'new'
at Function.init (<root>/node_modules/objection/lib/model/AjvValidator.js:24:28)
at new Validator (<root>/node_modules/objection/lib/model/Validator.js:5:22)
at new AjvValidator (<root>/node_modules/objection/lib/model/AjvValidator.js:15:1)
at Function.createValidator (<root>/node_modules/objection/lib/model/Model.js:341:12)
at getValidator (<root>/node_modules/objection/lib/model/Model.js:874:21)
at cachedGet (<root>/node_modules/objection/lib/model/Model.js:867:61)
at Function.getValidator (<root>/node_modules/objection/lib/model/Model.js:391:12)
at validate (<root>/node_modules/objection/lib/model/modelValidate.js:26:32)
at Observation.$validate (<root>/node_modules/objection/lib/model/Model.js:97:12)
at GraphInsertAction._insert (<root>/node_modules/objection/lib/queryBuilder/graph/insert/GraphInsertAction.js:177:16)
at GraphInsertAction._insertBatch (<root>/node_modules/objection/lib/queryBuilder/graph/insert/GraphInsertAction.js:48:16)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
When reviewing objection/lib/model/AjvValidator.js:24:28 I see ambiguous JavaScript syntax:
// Create a normal Ajv instance.
self.ajv = new getAjv()( // <-------------------- ISSUE
Object.assign(
{
useDefaults: true,
},
self.ajvOptions
)
);
// Create an instance that doesn't set default values. We need this one
// to validate `patch` objects (objects that have a subset of properties).
self.ajvNoDefaults = new getAjv()( // <-------------------- ISSUE
Object.assign({}, self.ajvOptions, {
useDefaults: false,
})
);
Below is a modified version that never throws this error for me, unambiguous JavaScript syntax:
const AJV = getAjv()
// Create a normal Ajv instance.
self.ajv = new AJV(
Object.assign(
{
useDefaults: true,
},
self.ajvOptions
)
);
// Create an instance that doesn't set default values. We need this one
// to validate `patch` objects (objects that have a subset of properties).
self.ajvNoDefaults = new AJV(
Object.assign({}, self.ajvOptions, {
useDefaults: false,
})
);
Get this error in Node
v14.16.0
when doinginsert
operation usingobjection@v2.2.15
whenajv@8
is locked (by other dependencies):When reviewing
objection/lib/model/AjvValidator.js:24:28
I see ambiguous JavaScript syntax:Below is a modified version that never throws this error for me, unambiguous JavaScript syntax:
My environment for the record: