[SOLVED] Unity 2020 WebGL Doesn't work Uncaught SyntaxError: Invalid or unexpected token

Error in chrome:

Uncaught SyntaxError: Invalid or unexpected token
entershadowweb4.loader.js:1 Uncaught ReferenceError: unityFramework is not defined
    at HTMLScriptElement.n.onload (entershadowweb4.loader.js:1)
entershadowweb4.loader.js:1 [UnityCache] 'http://192.168.56.1:8000/entershadowweb4/Build/entershadowweb4.data.gz' successfully downloaded and stored in the indexedDB cache

Win10. 2020.2.0a7. Same with 2020.1.

I’m testing a build using miniweb of [enter shadow] by iwanPlays but I also created a fresh empty project with 2020.2.0a7 and got the same result. Optimized for speed, not size.

4MB web built package: webtest1.zip - Google Drive

5 Likes

Solution: Disable compression.

Solution found thanks to Unity 2020.1 - Invalid or unexpected token error from compressed framework.js file

8 Likes

Hey, I’m pretty new to unity and want to put my first game on itch.io.
However, whenever I run the ZIPPED file in the unpublished draft, it says “invalid token ‘<’”
PLEASE HELP!

same problem invalid token “<”

disabling compression is a very bad caveman solution

8 Likes

Any other solutions?

An error “Uncaught SyntaxError: Invalid or unexpected token” or "“invalid token ‘<’” suggests that the compression setting did not match with the server hosting configuration:

either the server is set to host pre-compressed content (by enabling the Content-Encoding: gzip HTTP response header on the resources), but the files that have been uploaded to the server are not actually pre-compressed; or

the server is not set to host pre-compressed content (no Content-Encoding: gzip HTTP response header is configured), but the files that have been uploaded have been pre-compressed.

That is, the two things need to match: if one uploads uncompressed content, then “Content-Encoding: gzip” HTTP response header must NOT be present in the server configuration, and if one uploads precompressed content, then “Content-Encoding: gzip” HTTP response header MUST be present in the server configuration.

Not familiar with how itch.io configures its hosting, but maybe there is a way to toggle the “Content-Encoding: gzip” in its configuration system?

3 Likes

Enable decompression fallback

https://docs.unity3d.com/2020.2/Documentation/Manual/webgl-deploying.html

9 Likes

Thanks for this fallback solution!! This works for me. Had to get this up before the morning and I don’t have access to our servers, so this was a great solution until we can make that change. It loads slowly for now, but at least it loads. And I’m assuming it loads at least a bit more quickly than skipping compression altogether.

I added this code to “index.html”;

<meta http-equiv="content-encoding" content="gzip" />

And “.htaccess” file has this code;

<IfModule mod_mime.c>
  AddEncoding gzip .unityweb
  AddEncoding gzip .wasm
  AddType application/wasm .wasm
</IfModule>

But it doesn’t work. I have to put this code to another place? Where? And did you mean a code like this or i have to use a different code?

1 Like

“Disable Compression” is not a real solution. Why you wrote “[SOLVED]”? :slight_smile:

2 Likes

I have never before seen that kind of http-equiv line. Do you have a reference about this? (my google turned up nothing) In my current understanding that cannot work because a) meta directives should only apply to the file they are in (in this case index.html), and b) the directive is inside the very content that is to be compressed, so a browser should successfully decompress the content first to get to know what the compression is? (a chicken-and-an-egg problem)

This looks good to me Are you using Apache web server? Are there any errors in the log? Are mod_mime & mod_deflate enabled? Are .htaccess files enabled? Check out e.g. https://discussions.unity.com/t/698111

“Disable Compression” is the real solution if the web hosting one is using already employs on-demand caching server-side compression. When hosting content on such a server, users should disable compression in Unity builds.

1 Like

I meant if older versions of Unity doesn’t have this problem, How this can be a real solution? It is a new problem on Unity 2020. Is this a bug? Or older versions of Unity have bug?? :smile: Sorry, i am just asking these questions to myself for many months. :smile:

The only difference between older Unity versions and newer versions is that we have changed the default settings: starting from 2020.1, software compression fallback is disabled by default; whereas in older versions it was enabled by default. That is what makes it look as if Unity 2020.1 has a “bug”. If you enable software decompression fallback, you will get old behavior back.

The core thing here is that nobody should be using software compression fallback. Sure it will have the effect of making the page load, but at great expense to startup times if the server configuration is not correct. That in turn will lead to people blaming Unity that Unity is slow to start up in the browser, when in reality the issue was that the hosting web server did not have the correct configuration.

Hence we want to switch gears and push developers towards the right performant solution out of the box: get the server configuration right.

Unfortunately the way that this change landed in Unity 2020.1, the startup experience missed good diagnostics messages to explain when server compression was misconfigured. We have just recently improved this, so next Unity point release should print out more helpful messages at startup if server compression configuration is not properly set up.

10 Likes

Key information is this. :slight_smile:

2 Likes

Can you point me to a good source or documentation for the right way for server configuration. Thanks for the post.

here; :slight_smile:
https://docs.unity3d.com/2020.1/Documentation/Manual/webgl-server-configuration-code-samples.html

It is maybe worth to add, how to check if compression is enabled on server side:

gzip:
$ curl -I -H ‘Accept-Encoding: gzip’ https://www.myDomain.asdf

brotli:
$ curl -I -H ‘Accept-Encoding: br’ https://www.myDomain.asdf

The response will be something like this:

HTTP/1.1 200 OK
Server: Apache/2.4
ETag: “ff5-5a044b137d5c0-gzip”
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 1574
Content-Type: text/html

1 Like

This is still broken with no useful error message.

The improved error messages have landed in to Unity 2021.1.0a4 in November 2020, with a backport request active for Unity 2020.2, but that has unfortunately not yet landed. If possible try checking out Unity 2021.1.0b4 Pre-Release where the improved error messages should exist.