zloirock / core-js

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

Regression on use URLSearchParams pollyfil #1380

Open nachocodoner opened 1 week ago

nachocodoner commented 1 week ago

Hello,

As part of the Meteor framework, we used core-js to polyfill URLSearchParams and URL in legacy builds. This is essential for supporting older browsers and Cordova webviews. We have recently faced an issue we solved by using a new polyfill for URLSearchParams. But we think this may be a regression on core-js after latest versions.

Initially, we used core-js version 3.14.0 and everything worked well. After the upgrade to latest version, the code broke, and legacy handling stopped working.

Previously, we imported these polyfills using require("core-js/proposals/url"); (source). However, with latest core-js version (unsure which), legacy browsers now throw the error: TypeError: undefined is not an object (evaluating '$URLSearchParams.prototype').

Even when switching to require("core-js/web/url-search-params"), the same error occurs. This is the part of code involved on the problem.

It seems this issue could be a regression or that a newer version no longer offers URLSearchParams as a polyfill. I would like to get a confirmation, I didn't find a reference on this, or the way we should use it now..

zloirock commented 1 week ago

You could have this issue if web.url-search-params.constructor module is not imported before web.url-search-params.delete. URLSearchParams -> $URLSearchParams.prototype is defined in this module.

Both - core-js/proposals/url and core-js/web/url-search-params should import them as expected, so I have no concrete idea why you have this problem. Note that those entries are obsolete and I recommend using, for example, core-js/actual/url-search-params.

zloirock commented 1 week ago

The most likely cause of your problem is that you could have incorrect optimization Babel / SWC settings. If your transpiling target engines have basic support of URLSearchParams, but have not support of second argument of URLSearchParams#delete, core-js entries used by you will be replaced only to core-js/modules/web.url-search-params.delete without web.url-search-params.constructor. If you will run it in engines without native URLSearchParams support, you will have this error.