Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

480
Visualizações
AssertionError [ERR_ASSERTION]: you must pass Joi as an argument

How do I solve this Joi problem(Using express, joi@17.4.2,joi-objectid@2.0.0, ,mongoose) I am trying to link two mongoose schemas using ref as

{
...
   enroledcourses: [{
        type: Schema.Types.ObjectId,
        ref: "courses"
    }]
}

joi validation

...    
enroledcourses: Joi.array().items(Joi.ObjectId()).required()

the course collection is fine i have imported it at index.js as below

const Joi = require("joi")
Joi.objectId = require("joi-objectid")(Joi);

but i end up getting this error enter image description here

AssertionError [ERR_ASSERTION]: you must pass Joi as an argument at joiObjectId (D:\Programing projects\2021\ikodeafrika\ikodeafrikabackend\node_modules\joi-objectid\index.js:6:3) at Object. (D:\Programing projects\2021\ikodeafrika\ikodeafrikabackend\index.js:2:39)

index.js:2:39 being the joi.objectId import above plus i'm getting this when i hover over the joi.objectId import statement

Property 'objectId' may not exist on type 'Root'. Did you mean 'object'?ts(2568) index.d.ts(1998, 9): 'object' is declared here. any

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem is because joi-objectid@2.0.0 is not compatible with joi@17.4.2.

Fix:
Upgrade joi-objectid to v4.0.2

About the Typescript error (Property 'objectId' may not exist on type 'Root'), you need to augment the type of Joi to add the objectId property. This can be done by creating a declaration file:

// src/types/joi.d.ts
import { Schema } from "joi";

declare module "joi" {
  interface Root {
    objectId(): Schema;
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda