• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

195
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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error