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

175
Visualizações
Check if an asset exists before dinamically importing it

Hello I'm trying to dynamically import a file and if it doesn't than I'm going to create it. But how can I import it only if it exists? This code is throwing me a 500 server error when I try to import a not existing yet file. This is my code (I'm using Vite to serve my app)

import(`./../Cache/${component.type.name}.svg?raw`)
.then(svgCode => console.log(svgCode))
.catch(err => {
    //here the file is created if it doesn't exists but it still throwing an error in the console
  })

It's not only about the error in the console, Vite is also throwing me this message:

ENOENT: no such file or directory, open '/Atlantide/SvgRender/Cache/PixelGrid.svg' Click outside or fix the code to dismiss. You can also disable this overlay by setting server.hmr.overlay to false in vite.config.js.

But I don't wanna disable HMR in my setup, any advice?

about 4 years ago · Santiago Trujillo
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