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

398
Visualizações
Error using the library xml2js with React and TypeScript

I have a React app that needs to parse some XML data. I plan to use a package to do this job. The packages xml2js and @types/xml2js are installed. During testing the following error appeared:

sax.js:222 Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
    at sax.js:222:46
   ...

Here's the file containing the code. The syntax should be correct according to the docs. The other components shouldn't be causing this particular error since they are not wired to it yet.

import {useState, useEffect} from 'react'
import x2j from 'xml2js';

export default function EventWindow(props: { xml: string; }) {
  const {xml} = props;
  const [eventText, setEventText] = useState('');
  const [eventChoices, setEventChoices] = useState('');

  useEffect(() => {
    const ps = new x2j.Parser();
    ps.parseString(xml, (err, res) => {
      console.log(res)
    })
  }, [xml])

  return (
    <div>
      <EventSimText text={eventText || "Error Detected."} />
      <EventSimChoices choicesArr={eventChoices} />
    </div>
  )
}

Thanks

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

0

Problem details are required before correcting. For example, screenshots 🔍

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