Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by SteenPetersen · Aug 22, 2017 at 07:47 PM · webglsyntax-error

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.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SteenPetersen · Aug 23, 2017 at 07:06 AM 0
Share

Anyone at all got any idea how to fix this?

avatar image Hopsasasa · Aug 28, 2019 at 11:19 AM 0
Share

Does not work for me. Still says unexpected token??

avatar image Hopsasasa · Aug 28, 2019 at 12:22 PM 0
Share

Does not work for me. Still says unexpected token??

6 Replies

· Add your reply
  • Sort: 
avatar image
17
Best Answer

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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jordanks · Mar 19, 2018 at 02:40 AM 0
Share

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>
avatar image JoanneChilds · Apr 22, 2018 at 07:39 PM 0
Share

Thank You So $$anonymous$$uch! You literally just saved my life :)

avatar image argentummanusbeta JoanneChilds · Apr 24, 2018 at 03:27 PM 0
Share

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

avatar image SimplyMagic · Mar 12, 2020 at 10:23 AM 0
Share

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>
avatar image SteenPetersen SimplyMagic · Mar 12, 2020 at 10:27 AM 0
Share

No problem, glad I could help =)

avatar image BrainSlugs83 · Apr 17, 2020 at 08:10 AM 0
Share

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.

avatar image
2

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image stevencr4z · Oct 10, 2020 at 11:49 PM 0
Share

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

avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SteenPetersen · Aug 12, 2019 at 08:06 PM 0
Share

Glad I could help =)

avatar image
0

Answer by travs · Dec 31, 2018 at 04:43 PM

Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @SteenPetersen

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

86 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WebGL Build on Kongregate with Black Screen 0 Answers

WebGL error after hosting 1 Answer

WebGL Build resizes to 1280x720 when I open a specific scene, despite those dimensions never appearing in my code. 0 Answers

Is VideoPlayer support webgl? 1 Answer

Running one instance of webgl build at a time in a html page when loading webgl builds sequencially. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges