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