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

323
Visualizações
Uncaught TypeError: a is undefined

I have this:

let dateDataStartDate = moment().startOf('week')._d
let dateDataEndDate = moment().endOf('week')._d
if (datesData.start != undefined) {
  dateDataStartDate = datesData.start
  dateDataEndDate = datesData.end
}

axios.get('/api/classes/' + props.myVal, {
      params: {
          dateDataStartDate: dateDataStartDate,
          dateDataEndDate: dateDataEndDate,
          admin: true
      }
  })

when I run this code, I get this error:

Uncaught TypeError: a is undefined

and this error corresponds to this line from my console output:

let dateDataEndDate = moment().endOf('week')._d

Does anyone have any idea what the problem could be?

UPDATE

Problem was solved by fixing if (datesData.start != undefined) {

what was happening was that datesData is undefined, which means the object element .start doesn't exist. So it seems that I am trying to access a non-existent object element, and it was failing. So to fix it, I did:

if (datesData != undefined) {

weird, but it works

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

0

You can tell that the error is not within your code snippet

By the time the error occurs, in your 2nd line, there is no variable a.

let dateDataStartDate = moment().startOf('week')._d
let dateDataEndDate = moment().endOf('week')._d
if (datesData.start != undefined) {
  dateDataStartDate = datesData.start
  dateDataEndDate = datesData.end
}

axios.get('/api/classes/' + props.myVal, {
      params: {
          dateDataStartDate: dateDataStartDate,
          dateDataEndDate: dateDataEndDate,
          admin: true
      }
  })

If the error really is coming from that line, then it can't be from failure to define moment(), since it got past the first line.

Therefore there must be something wrong with the moment software, and probably in its endOf() module.

As @Mithiridi Prasanth says, do check that you are using an up to date version of NodeJs.

Debugging

Remove all the lines except the line causing the error

Are you still getting the error, and in the same line?

That line is not using any variables previously declared, and the later lines can't be the cause of the earlier error, if you are right about the site of the error.

Try a less deep access into moment()

let test1 = moment()
let test2 = moment().endOf
let test3 = moment().endOf('week')
let test4 = moment().endOf('week')._d

And console.log the results. That way you can see at what stage it is going wrong.

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