{"record":{"id":"ac5e355f53e8d30e","repo":"serverless/serverless","slug":"unexpected-non-function-ajv-validator-type-please","errorCode":null,"errorMessage":"Unexpected non-function AJV validator type. Please report at https://github.com/serverless/serverless including all the logs output","messagePattern":"Unexpected non-function AJV validator type\\. Please report at https://github\\.com/serverless/serverless including all the logs output","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/serverless/lib/classes/config-schema-handler/resolve-ajv-validate.js","lineNumber":101,"sourceCode":"    await fsp.writeFile(tmpCachePath, moduleCode)\n    await safeMoveFile(tmpCachePath, cachePath)\n    await fsp.rmdir(tmpDir)\n  }\n\n  await ensureExists(cachePath, generate)\n  const loadedModuleCode = await fsp.readFile(cachePath, 'utf-8')\n  const validator = requireFromString(\n    loadedModuleCode,\n    path.resolve(__dirname, `[generated-ajv-validate]${filename}`),\n  )\n\n  if (typeof validator !== 'function') {\n    log.error(\n      'Unexpected validator %o, resolved from source %s',\n      validator,\n      loadedModuleCode,\n    )\n    throw new Error(\n      'Unexpected non-function AJV validator type. Please report at https://github.com/serverless/serverless including all the logs output',\n    )\n  }\n\n  cachedValidatorsBySchemaHash[schemaHash] = validator\n  return validator\n}\n\nexport default getValidate\n","sourceCodeStart":83,"sourceCodeEnd":111,"githubUrl":"https://github.com/serverless/serverless/blob/b9d7ea51c8cce57cff1207964b9b71123673081f/packages/serverless/lib/classes/config-schema-handler/resolve-ajv-validate.js#L83-L111","documentation":"Thrown after loading a previously-generated AJV standalone validator from the on-disk cache. resolve-ajv-validate.js reads the cached JS module via requireFromString and checks that the result is a function (the validate function). If it is not a function (e.g., undefined, an object, or a corrupted module), it logs the unexpected value and source code, then throws a plain Error. This is an internal integrity check — it should never fire under normal conditions.","triggerScenarios":"The cached validator file at ~/.serverless/artifacts/ajv-validate-<date>/<hash>.js is corrupted, truncated, or overwritten by another process. requireFromString returns a non-function (partial module, empty file, or a module whose default export was lost). Can also occur if the AJV standalone code generation produced an invalid module due to an AJV version mismatch.","commonSituations":"A crashed or interrupted run left a half-written cache file. Another tool or antivirus modified files in the .serverless cache directory. Disk corruption. An AJV version bump changed the standalone code output format while old cached modules remain.","solutions":["Delete the AJV validate cache: rm -rf ~/.serverless/artifacts/ajv-validate-* and re-run — the framework will regenerate the validator.","If the issue persists, set SLS_SCHEMA_CACHE_BASE_DIR to a writable temp directory to rule out permission issues.","Report the issue at https://github.com/serverless/serverless with the logged source code output.","Check for concurrent Serverless processes that might race on the same cache directory."],"exampleFix":"# before — corrupted cache causes non-function validator\n# (error on deploy)\n\n# after — clear cache and retry\nrm -rf ~/.serverless/artifacts/ajv-validate-*\nserverless deploy","handlingStrategy":"fallback","validationCode":"// Before running, check if the cache directory is writable and clean\nconst fs = require('fs')\nconst path = require('path')\nconst os = require('os')\nconst cacheDir = path.join(os.homedir(), '.serverless', 'artifacts')\ntry {\n  fs.accessSync(cacheDir, fs.constants.W_OK)\n} catch {\n  console.warn('AJV cache dir not writable; consider setting SLS_SCHEMA_CACHE_BASE_DIR')\n}","typeGuard":null,"tryCatchPattern":"// Wrap framework invocation; on cache corruption, clean and retry\nconst { execSync } = require('child_process')\ntry {\n  execSync('serverless deploy', { stdio: 'inherit' })\n} catch (e) {\n  if (e.stderr && e.stderr.includes('Unexpected non-function AJV validator')) {\n    execSync('rm -rf ~/.serverless/artifacts/ajv-validate-*')\n    execSync('serverless deploy', { stdio: 'inherit' })\n  } else {\n    throw e\n  }\n}","preventionTips":["Add a pre-deploy cache cleanup step in CI to avoid stale validator files.","Avoid running multiple Serverless processes concurrently in the same home directory.","Ensure the .serverless directory has stable write permissions.","Report persistent occurrences to the Serverless team with full logs."],"tags":["ajv","cache","internal-error","validator"],"backgroundTag":null,"analyzedSha":"b9d7ea51c8cce57cff1207964b9b71123673081f","analyzedAt":"2026-08-13T04:14:40.386Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}