question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned.

See original GitHub issue

When 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
tofumattcommented, Oct 11, 2016

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?

5reactions
tofumattcommented, Oct 12, 2016

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found