vite ajv codegen __vite_ssr_import_1__

57 Views Asked by At

I want to use ajv codegen that essentially calls some external function, that I cannot completely rewrite using codegen.

import { dbGetNumberOfUsers } from 'path/to/my/file'

const newUser : KeywordDefinition = {
  keyword: "newUser",
  async: true,
  schemaType: "boolean",
  validate: async (schema : true, data: any) => (await dbGetNumberOfUsers(data)) === 0 
  /*,
  code(cxt: KeywordCxt) {
    const {data, gen} = cxt
    let number = gen.const('number', _`await dbGetNumberOfUsers(${data})`)
    cxt.fail(_`${number} !== 0`)
  }
  */
}

Problem is using codegen, dbGetNumberOfUsers is undefined, and if I try validate or compile, I get error __vite_ssr_import_1__.dbGetNumberOfUsers is not a function , which likely means some kind of vite hmr errors that hopefully I can bypass if codegen works. I probably need both gen.code and gen.const in a single statement, but not sure how. I am new to ajv codegen, thanks in advance for all your help!

EDIT: So it seems that this is at its core, a vite issue. Codegen upon Codegen. Please let me know how to get Ajv to recognize the function. Thanks

0

There are 0 best solutions below