Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

WebGL Build Issues Using WebSocket Plugin

Discussion in '2021.2 Beta' started by Doddler, Aug 1, 2021.

  1. Doddler

    Doddler

    Joined:
    Jul 12, 2011
    Posts:
    269
    I've been messing around with trying to get websockets and WebGL to play nicely and have run into a number of issues involving the latest beta. I want to say that I've tested these all of these steps in 2020.3.14f1 and there were no errors at any point.

    First, when manually adding the following package via git, WebGL builds stop working. Package url: https://github.com/endel/NativeWebSocket.git#upm

    I would normally pin this on the package in question, but the build error is pretty weird and suggests something is going on with unity. Here's the error message it returns:

    Code (csharp):
    1. Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
    2. emcc:WARNING: --llvm-lto ignored when using llvm backend
    3. emcc2: error: '--js-library': file not found: 'Packages/com.endel.nativewebsocket/WebSocket/WebSocket.jslib'
    4. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    This suggests the build process is... unable to find the file? When adding all the project files directly to the project, rather than using the package manager, the error no longer occurs.

    Problem 2, is that the plugin appears to break the build pipeline with some cryptic messages.

    Code (csharp):
    1. Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
    2. emcc:WARNING: --llvm-lto ignored when using llvm backend
    3. emcc2: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
    4. G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\tools\acorn-optimizer.js:1845
    5.   throw err;
    6.   ^
    7.  
    8. SyntaxError: Unexpected token (3434:62)
    9.   var textEncoder={encoding:"utf-8",encode:encode(input = '') {
    10.                                                               ^
    11.  
    12.     at Parser.pp$4.raise (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:2927:15)
    13.     at Parser.pp.unexpected (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:698:10)
    14.     at Parser.pp.expect (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:692:28)
    15.     at Parser.pp$3.parseObj (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:2563:14)
    16.     at Parser.pp$3.parseExprAtom (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:2302:19)
    17.     at Parser.pp$3.parseExprSubscripts (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:2129:21)
    18.     at Parser.pp$3.parseMaybeUnary (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:2106:19)
    19.     at Parser.pp$3.parseExprOps (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:2041:21)
    20.     at Parser.pp$3.parseMaybeConditional (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:2024:21)
    21.     at Parser.pp$3.parseMaybeAssign (G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\node_modules\acorn\dist\acorn.js:1997:21) {
    22.   pos: 131783,
    23.   loc: Position { line: 3434, column: 62 },
    24.   raisedAt: 131784
    25. }
    26. emcc2: error: 'G:/Programs/Unity/2021.2.0b4/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/node/node.exe G:\Programs\Unity\2021.2.0b4\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\tools\acorn-optimizer.js C:\Users\doddl\AppData\Local\Temp\emscripten_temp_4pj4n9ip\build.js.pp.js AJSDCE minifyWhitespace' failed (1)
    27. UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
    28. Assets.Scripts.Editor.BuildAddressablesProcessor:BuildPlayerHandler (UnityEditor.BuildPlayerOptions) (at Assets/Scripts/Editor/BuildAddressablesProcessor.cs:46)
    29. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    I couldn't figure this one out as I could not find the code highlighted as causing the error anywhere. Where it comes from, I don't know. The plugin does take on textencoder as a dependency, so I figure the source may be from that. This plugin works fine in unity 2020.3.14f1, but I'm at a loss as to why it may not function here.

    At very least, even if this was a bug with the plugin and not a regression, I'd consider these poor error messages a bug still. The plugin is rather tiny and could be used to reproduce the issue.
     
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
  3. kentakang

    kentakang

    Joined:
    Oct 12, 2021
    Posts:
    1
    iurii_ivanov and jeffreylanters like this.
  4. pajamajama

    pajamajama

    Joined:
    Oct 22, 2012
    Posts:
    66
    @LeonhardP that ticket says fixed in 2021.2.x, but I get the same errors in 2021.3.3
    Is there a way to reopen that ticket?

    I'm using a different plugin. The fixes in the websocket library seem unrelated. But these logs from Unity are not very helpful.

    Thanks!
     
  5. alpdogan

    alpdogan

    Joined:
    May 8, 2015
    Posts:
    10
    Last edited: Nov 14, 2022