Replies: 1 comment
-
Parcel doesn't know that you're using that json file, so it's not copied into the dist folder. Then the dev server responds with the index.html file. You could either do (If this were a PNG file or some other asset, you could use https://parceljs.org/languages/javascript/#url-dependencies . But that doesn't work for JSON right now.) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all!
Recently I've been trying to use data.json file in my main.js code, however the console throws an error: SyntaxError: Unexpected token '<', " <!DOCTYPE "... is not valid JSON. Seems like, there is an issue in a way parcel handles JSON. I tried the same code without parcel everything worked fine.
I checked the content-type value under the promise header and it was set to text/html; Charset= utf-8. So, apparently parcel transforms JSON to text/html instead of Application/json.
I added an .htaccess configuration file to the directory where my JSON file is located with the following code:
AddType application/json .json.
However, it did not help. The status code of a promise is 200. So, there is no mistake in a fetch function:
If somebody has ever encountered to the same problem, would very much appreciate the help!
I also include my package.json code:
Beta Was this translation helpful? Give feedback.
All reactions