Search code examples
javascriptes6-promise

Why is this Promise not getting resolved?


I created a function that reads an external JSON file and returns a promise. It was working fine but suddenly stopped working. Here's my code where the error is occuring.

export let readJSON = async (file) => {
    const request = async () => {
        const response = await $.get(`${jsonPath}/${file}`);
        return response; 
    }
    return await request();
}

Here's the function call

readJSON("admin-form.json").then( i => {
        let opts = $.extend({}, i, options )
        formBuilder(opts);
    } ).catch(e => console.error(e))

and here's the error that I am getting in console enter image description here

I even changed my code to

export let readJSON = async (file) => $.get(`${jsonPath}/${file}`)

readJSON("admin-form.json").then( i => {
        console.log(i)
    } ).catch(e => console.error(e))

but error remains.

It was working fine then suddenly stopped working


Solution

  • There was a parse error in my json file that I was trying to read admin-form.json