DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned.
See original GitHub issueWhen i setItem then get error
DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned.
my code:
this.cacheOrders.push(order);// success!
let str = JSON.stringify(this.cacheOrders);// success!
console.log(JSON.parse(str));// success!
return localForage.setItem(this.cacheOrdersKey,this.cacheOrders);// error!
if i change
return localForage.setItem(this.cacheOrdersKey,this.cacheOrders);
to
return localForage.setItem(this.cacheOrdersKey,JSON.stringify(this.cacheOrders));
then success,If so, why would I want to use localForage.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
IndexedDB error: Uncaught DataCloneError: Failed to execute ...
marker can't be cloned because the object stored in the map -property contains a reference to a DOMNode( #map-overview ), which can't be ......
Read more >IndexedDB error: Uncaught DataCloneError: Failed to execute ...
Javascript – IndexedDB error: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned.
Read more >Data clone error - Ionic Forum
could not be cloned. Error: Failed to execute 'put' on 'IDBObjectStore': function (responseObserver) { var _xhr = browserXHR.build();.
Read more >Dexie.DataCloneError
An attempt to add or put an item into the database was made, where the object contained a strucure not supported by the...
Read more >Failed to execute 'put' on 'IDBObjectStore': An object could not ...
DOCTYPE html> <html> <head> <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.js"></script> <script ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
localForage’s IndexedDB driver doesn’t serialise the data to JSON before storing it; it directly stores the data you pass it into IndexedDB.
So it seems you have some data that can’t be cloned (objects referencing another maybe, etc.). If you want you can manually serialise and deserialise the data, but that means you will lose some of the data you’re storing.
What does the object you’re trying to store look like?
Ah, okay, if the object contains a function it can’t be stored inside a database as it can’t save functions.
You’ll need to remove the function from the object you’re trying to save before saving it. You can see the types of objects localForage can store here: https://localforage.github.io/localForage/#data-api-setitem