Svelte – list of bugs and their fixes

1 min


Correction of common errors on svelte.

TypeError: Object of type datetime is not JSON serializable

From the Python side, the data transfer is not correct. Data should be transmitted in json format.

Examples:

json.dumps(my_dictionary, indent=4, sort_keys=True, default=str)

or

return json.dumps(last_price(name), separators=(‘,’, ‘:’))

or

return json.dumps(last_price(name))

Error: {#each} only iterates over array-like objects

We must explicitly declare that our variable will be an array:

Uncaught Error: {#each} only iterates over array-like objects.

or
[object Promise] svelte

Mistake:

index.mjs: 1569 Uncaught Error: {#each} only iterates over array-like objects.
at validate_each_argument (index.mjs: 1569)
at Object.update [as p] (App.svelte: 139)
at update (index.mjs: 707)
at flush (index.mjs: 676)
at init (index.mjs: 1439)
at new App (App.svelte: 120)
at app.js: 3
at app.js: 8

The solution will not necessarily be like the example below. There are many reasons that could be associated with this error.

AND

The bottom line is that there is no time to receive data from the backend, which is then iterated on the Svelte side. At the moment when a variable in Svelte is initialized, there is still no data in it.

Add asynchrony to JS:

GeSHi Error: GeSHi could not find the language javasript (using path /home/admin/web/ploshadka.net/public_html/wp-content/plugins/codecolorer/lib/geshi/) (code 2)

B

We put the received data into an iterable data array, and not just into a variable:

let stocks = [[];
stocks = Arrayfrom(items[[1]);

Uncaught (in promise) SyntaxError: Unexpected token O in JSON at position 0 awate

Probably the data coming from the backend is not in JSON format. We fix:

return json.dumps(response)

Uncaught (in promise) TypeError: Failed to execute ‘json’ on ‘Response’: body stream is locked

If you try to read the response twice, then this error can occur. Those. code like this might throw an error:

console.log(response.text());
response.json()

In this case, you should remove the console.log and everything will work.


0 Comments

Leave a Reply