Minification produces invalid Javascript

Alright, after a lot of hair loss I’ve narrowed down a very significant bug.

I have a SvelteKit site (which uses Vite under the hood) and it’s using auth0-spa-js, which pulls in core-js.
The issue appears because core-js uses a weird syntax to get the toString function of a number, like so:
1.0.toString
this will then windup getting minified to
1 .toString
which is perfectly valid javascript.

The issue comes with CF, after it applies it’s own minification:
1 .toString
turns into:
1.toString
which is invalid javascript.

Disabling minification in Vite doesn’t work, as:
1.0.toString
will still get minified by CF, to:
1.toString
which is still invalid javascript.

My only solution has been to disable Cloudflare’s minification of Javascript, which is barely a solution as we have other subdomains that benefit from having minification enabled. Any thoughts for a better temporary fix are appreciated. Cheers.

(Links are not allowed, but you can see the weird syntax yourself in uid.js (ln#5) in the core-js repo.)

2 Likes

You can use Page Rules to disable Auto Minify for a specific URL/pattern, rather than doing it on the entire zone.

2 Likes

Yep, got suggested this by another person as well. I’ve done that now and now the rest of site is happy. Still would like to see this issue resolved though.

Facing the same issue. We have the combination of Vite + Auth0-SPA, which uses core-js which produces that Bad Minify.

1 Like