Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!