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

254
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
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!