0

I am trying to read json file from local, but as a response I am getting an error look like this

Fetch API cannot load file:///var/www/desktop-electron//dashboard/bnb.json. URL scheme "file" is not supported

Here is my code

fetch(`${drr}/dashboard/bnb.json`)
            .then(res => res.json())
            .then(res => {
                this.currency = res;

                Object.assign(this.stock, res.pairs[0]);
                Object.assign(this.header, res.pairs[0]);
                this.header.name = res.name;
            }).catch(function(e) { console.log(e) });

I have read all solutions which from google ,but can not solve the problem!

2 Answers 2

1

have you tried to omit the "file://" scheme altogether? Also first try to wrap the URI in a Request Object, like described here

fetch(new Request(URI))
Sign up to request clarification or add additional context in comments.

Comments

0

Native fetch (Chromium) doesn't support to load resources from local via file protocol. In short you can't, you need to use other way around (like fs.readfile, or some other means) or host json to remote endpoint to use fetch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.