Javacript error - Error compiling schema (AJV related)

Hi all!

I am experiencing a strange problem.
My json form (in Angular) is rendering without problems when running from Visual Code with ng serve.
But when running the application from Azure I get this error in the console while rendering the form:

Error compiling schema, function code: const schema2 = scope.schema[2];const schema1 = scope.schema[1];return function validate3(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(!((typeof data == "number") && (!(data % 1) && !isNaN(data)))){const err0 = {instancePath,schemaPath:"#/definitions/nonNegativeInteger/type",keyword:"type",params:{type: "integer"},message:"must be integer",schema:schema1.type,parentSchema:schema1,data};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}if(typeof data == "number"){if(data < 0 || isNaN(data)){const err1 = {instancePath,schemaPath:"#/definitions/nonNegativeInteger/minimum",keyword:"minimum",params:{comparison: ">=", limit: 0},message:"must be >= 0",schema:0,parentSchema:schema1,data};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}}validate3.errors = vErrors;return errors === 0;}

Did any of you see this error before? What could it be?

new info: It seems to be related to AJV

Problem was caused by the Content-Security-Policy header!

The underlying exception was: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'unsafe-inline'"

The problem was solved by adding ‘unsafe-eval’ to the ‘script-src’ part of my Content-Security-Policy settings.

1 Like

Hi @cornelos,

AJV does code-gen internally and therefore requires the unsafe-eval option. If you’re not able to use unsafe-eval then there is a workaround if you know all schemas beforehand. See here for more information.

1 Like