- Home /
WebGL build error :Uncaught SyntaxError: Unexpected token < || UnityLoader.js is not a function (SOLVED)
I have uploaded my game to a webhost unoeuro woth the index.html the build d a templatedata folders and then launching the index.html I get the aforementioned error.
I google a bit and it seems its because the .htaccess file needs to be editted to fix this however, I can find no such file in my build and therefore I cannot fix this. wondering if anyone could guide me a bit here?
thanks.
Answer by SteenPetersen · Aug 25, 2017 at 11:05 PM
So I solved this issue, But it has been really frustrating as many of the people discussing this issue really assume a lot of their readers know a great deal about uploading files to a webserver. so I am going to be wrtting the very basics here for anyone having this issue:
If you have bought a webhotel, a website where you can place files. and you have uploaded your game to that website in webgl. You are trying to upload the (1) Index.html file, which is the main file that runs the game, (2) the templateData folder that has all the graphics for the website that unity creates for you, and (3) the Build folder that contains all the data for your game.
The issue is that all the ending of the files cannot be read by the webserver as they do not know what a ".unityweb" file is.
This needs to be told to the server so it knows what to do with them. On the web the files are recognized by something called a "MIME" type. you can read a good post on stack overflow about it here:
https://stackoverflow.com/questions/3828352/what-is-a-mime-type
In order to do this you will need to create your own extra file that unity does not create for you by default. I will run you through it here.
Open a new notepad text file.
Save this file as "web.config" somewhere you can find it, preferably in your game folder next to your index.html file
close notepad
doubleclick the web.config file and it should open in the integrated development environment (IDE) of your choice. most likely visual studio.
paste in the following code:
<configuration> <system.webServer> <staticContent> <mimeMap fileExtension=".unityweb" mimeType ="TYPE/SUBTYPE" /> </staticContent> </system.webServer> </configuration>
Save.
upload this file next to your index.html file.
cheer!
hope this helps someone. I would have killed for this information.
Basically this file is just letting the website know what MIME type "unityweb" is, and now it should know what to do with it.
thank you that was very useful, I think not all server have that problem. in my case, I have used Azure, i have problems even with json files, so i put it on the root folder this works for me
<system.webServer>
<staticContent>
<remove fileExtension=".json" />
<mime$$anonymous$$ap fileExtension=".json" mimeType="application/json; charset=UTF-8" />
<remove fileExtension=".unityweb" />
<mime$$anonymous$$ap fileExtension=".unityweb" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
Thank You So $$anonymous$$uch! You literally just saved my life :)
I Used this technique and its still giving me the same Error: Uncaught SyntaxError: Unexpected Token < in JSON at position 0
Is there something I am still missing
Thanks SteenPetersen Worked like a charm! Thank you!
This did the trick!
web.config file and it should open in the integrated development environment (IDE) of your choice. most likely visual studio.
paste in the following code:
<system.webServer>
<staticContent>
<mime$$anonymous$$ap fileExtension=".unityweb" mimeType ="TYPE/SUBTYPE" />
</staticContent>
</system.webServer>
</configuration>
FYI, the "TYPE/SUBTYPE" should absolutely be "application/octet-stream". -- "TYPE/SUBTYPE" isn't a real $$anonymous$$I$$anonymous$$E type, it's just the format that they are specified in. -- I'm not surprised it works though.
Answer by danielstegeman99 · Mar 25, 2020 at 01:18 PM
I would like to add a solution that works for asp.net hosting, since the web.config doesn't work. The following stackoverflow solution discribes how to add mime types in asp.net. https://stackoverflow.com/questions/51770084/how-to-add-mime-types-in-asp-net-core
Thank you very much! If anyone wants the straight-forward to using this solution in ASP.NET, the code is as follows:
// Set up custom content types -associating file extension to $$anonymous$$I$$anonymous$$E type
var provider = new FileExtensionContentTypeProvider();
// Add new mappings
provider.$$anonymous$$appings[".unityweb"] = "application/octet-stream";
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Build")),
RequestPath = "/Build",
ContentTypeProvider = provider
});
Drop that in your Configure() method in startup.cs and you should be set. But don't forget to have your appropriate web.config file placed in the /Build directory. You can find which code to use for that here: https://docs.unity3d.com/$$anonymous$$anual/webgl-deploying.html
Answer by shivamCode · Aug 12, 2019 at 03:17 PM
Thank you so much! I have been looking for the answer to this for about 3 hours now, and this solution works. Thank you.,Thank you so much. I have been trying to do this for 3 hours now, and this is a real solution. Thank you.
Answer by travs · Dec 31, 2018 at 04:43 PM
Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @SteenPetersen
Answer by ronaldvanmeer · Jun 02, 2019 at 09:31 PM
If your webhosting is linux / apache based Add the following line into the '.htaccess' file
AddType TYPE/SUBTYPE unityweb
,If your webhosting is linux / apache based:
Add the following line into the '.htaccess' file
AddType TYPE/SUBTYPE unityweb