zloirock / core-js

Standard Library
MIT License
24.61k stars 1.66k forks source link

3.32.0 : TypeError: Cannot assign to read only property 'structuredClone' of object '[object global]' #1281

Open jean-humann opened 1 year ago

jean-humann commented 1 year ago

Hello core-js community ✋,

I'm using core-js in my jest test here The test were working fine till dependabot open this PR to update version to 3.32.0 I have a new error in the jest test with 3.32:

TypeError: Cannot assign to read only property 'structuredClone' of object '[object global]'

      at Object.<anonymous>.module.exports (node_modules/core-js/internals/define-built-in.js:13:24)
      at Object.<anonymous>.module.exports (node_modules/core-js/internals/export.js:53:5)
      at Object.<anonymous> (node_modules/core-js/modules/web.structured-clone.js:6[12](https://github.com/jean-humann/docs-to-pdf/actions/runs/5808871705/job/15746546250?pr=157#step:5:13):1)
      at Object.<anonymous> (node_modules/core-js/full/index.js:450:1)
      at Object.<anonymous> (node_modules/core-js/index.js:2:18) 

Cf: https://github.com/jean-humann/docs-to-pdf/actions/runs/5808871705/job/15746546250?pr=157

Could you have a look please ?

joealden commented 1 year ago

FYI, I believe this is node version specific - v18 works fine, but v19 + v20 don't. I presume they made structuredClone unwritable in v19 - @zloirock are there other polyfills that exist already that work around this problem? Did something change in the latest core-js release that could have impacted this?

jean-humann commented 1 year ago

FYI, I believe this is node version specific - v18 works fine, but v19 + v20 don't. I presume they made structuredClone writable in v19 - @zloirock are there other polyfills that exist already that work around this problem? Did something change in the latest core-js release that could have impacted this?

You seem right, I deepdive in the gh actions history and I found this run where v18 works for the PR but not v19 and v20 : https://github.com/jean-humann/docs-to-pdf/actions/runs/5693855907/job/15510037805

zloirock commented 1 year ago

core-js is tested in those Node versions. They have an acceptable structuredClone descriptor:

image

It looks like a conflict with something else that rewrites and breaks structuredClone.

If it's a problem reproducible in the mentioned PR, I'll take a look at this little later.

joealden commented 1 year ago

If it helps, I believe it's specific to jest-environment-node - they are setting structuredClone here for use in node tests. With that being said, I'm still not sure why it's node version specific - it might help if I knew where jest environment classes are actually instantiated, but I don't have a great understanding of their codebase structure.

sibelius commented 1 year ago

is this a bug on core-js or jest ?

zloirock commented 1 year ago

@sibelius it's not a core-js or Node bug, something else overwrites structuredClone and makes it non-writable - Jest it or not - I still didn't check.