Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
Fetching local json file from JS module

I'm attempting fetch a local json file from a javascript module... My current file structure below.

enter image description here

I am currently working out of Map.main.js file and it currently looks like

class Map {
  constructor(el) {
    this.$el = el
    this.initMap()
  }

  initMap() {
    fetch('./map/data.json')
      .then((response) => response.json())
      .then((data) => console.log(data))
  }
}

export default Map

I am getting the following errors in the console

http://localhost:3000/map/data.json 404 (Not Found) VM2541:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

HTML is currently being compiled to the below (using twig)

enter image description here

enter image description here

I am not sure if makes a difference that I'm currently using babel/webpack to build my JS any help is appreciated thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

fetch('../../../json/map/data.json') should work using relative path and your files structure

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda