Returning a moment result object in transformer produces Failed to execute 'postMessage' on 'Window error

I noticed that if I return the result of a moment response as part of an transformer (e.g. return { date: moment() }), I get this error:

message:"Failed to execute 'postMessage' on 'Window': function(e){var a=e%10;return e+(1===k(e%100/10)?"th":1===a?"st":2===a?"nd":3===a?"rd":"th")} could not be cloned."

Just return moment() works (preview shows a string, although the response is typeof object), as does return { date: new Date() }.

There's some discussions here and here by @jssln and @brettski referencing 'Failed to execute 'postMessage' on 'Window'' errors, and perhaps this response, gets to the root of it.

The workaround seems to be to just return { date: new Date(moment()) }, which is probably what I wanted in the first place, since moment doesn't return a Date object anyway.

Still a weird error to get. Thought I'd post it in case someone else runs into it.

3 Likes

Thank you for such an incredibly thorough report. I've run into this many times, and I really appreciate you sharing the workaround for the other users that will inevitably run into this as well.

I've passed this to eng to get their eyes on this as well.

2 Likes

Hi @joostschuur,

Returning return { date: new Date(moment()) } is the same as saying return { date: new Date() }, which creates a new Date object as of the time it was called.

In both cases a stringified version of the date (e.g. 2022-12-05T15:29:36.243Z) will be sent along, returned.

Understood that this is the same thing. The specific bug only ocurrs when I send the result of a moment call back as part of an object (return { date: moment() }). The other examples I gave was just me showing what didn't trigger the error.

As it turns out, I didn't actually want the unprocessed result from moment either, so this is more of a general bug report that depending on the returned result, you might get a reallty confusing error message :slight_smile:

Yes, returning a moment object isn't very helpful in this case. Glad you have it all straightened out.

This is still an issue. Is the engineering team planning to address it?

Hello @Erik_Murphy!

I have not heard any updates internally on this issue. But I can ping it to see where the team is at!

Our of curiosity, why are you looking to return a moment Object?

Have you tried using the .format() method to return a string of the time which the object is holding?

I believe so. I don't remember which transformer gave me the issue now. I think I found some hacky way around it.

Returning a raw Moment is still not working and is on our list of fixes but it is not high on our priority list currently.

You should still be able to return the date string from the moment object.

Glad to hear you were able to find a work around. Let me know if you have any more details on the transformer that gave you issues or if you want to share the work around for other users to learn from!