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.)

5 Likes

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

3 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.

1 Like

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

3 Likes

I had the same issue. I am using Vite.
Disabling auto minification of JS solved this problem. This can be done in the settings Speed → Optimization → Auto Minify.

This is still an issue. Enabling JavaScript minification produces invalid JavaScript.

1 Like

Does anybody have a ticket# or test page we can escalate to Support to have them look into this?

1 Like

You can just make a vite-based project (vue, svelte, etc) and include auth0-spa-js.

You grossly overestimate my whatever-it-is-you’re-doing ability. :wink:

3 Likes

I’m having the same problem with Home Assistant and the Zigbee2MQTT addon (https://github.com/zigbee2mqtt/hassio-zigbee2mqtt). The Web GUI for Z2M does not load due to several instances of 1.toString in the minified code when minifying is enabled.

I think the problem is relative to core-js, fix could be made from them or from Cloudflare…vite minification work’s good, but Cloudflare break it.

I have the same exact issue.

Managed to get stack trace of the error with js minification:

index.c0cc3410.js:1 Uncaught SyntaxError: Invalid or unexpected token (at index.c0cc3410.js:1:5577)
    at t.activateScript (rocket-loader.min.js:1:11855)
    at rocket-loader.min.js:1:11052
    at t.run (rocket-loader.min.js:1:11259)
    at P (rocket-loader.min.js:1:3128)
    at Object.callback (rocket-loader.min.js:1:2851)
    at t.run (rocket-loader.min.js:1:11340)
    at rocket-loader.min.js:1:2907
    at rocket-loader.min.js:1:8117

It seems like issue is with Rocket loader CF feature.

For the reference issue on zigbee2mqtt github can be found here: https://github.com/zigbee2mqtt/hassio-zigbee2mqtt/issues/444#issuecomment-1423992751

core-js is producing valid JavaScript. Cloudflare’s minifier is the one acting incorrectly.