Reputation: 344
I just chased down wrong bugs for quite a while because code like
fetch("./garbage error message.json")
.then(res => res.json())
.then(res => { resourceLocations = res })
gave the error message (firefox browser)
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
The real error was that fetch
may have a different local directory than an import * from ...
statement in the same file if the file itself is imported.
I've come to realize I waste way too much time on trivial javascript errors, and wanted to ask for ways to remedy that.
Upvotes: 1
Views: 26
Reputation: 344
After the fact, I checked to see if the error message on chrome was any better, and got the following error messages instead:
Failed to load resource: the server responded with a status of 404 (Not Found)
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
which is a lot more helpful. Checking error messages on multiple browsers was not a strategy I'd employed before, but it would've helped me here.
A less easy solution I'm considering is learning either Nim or TypeScript to help with dynamic typing errors, but I can't vouch for what I haven't tried.
Upvotes: 1