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

255
Visualizações
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 Respostas
Responde à pergunta

0

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

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