I'm trying to build my multiplayer game to WebGL in Unity (using Mirror). However, when I press "build", it gives me the following three errors:
Building Builds\Web\index.html failed with output:
(node:78892) ExperimentalWarning: The ESM module loader is experimental.
file:///[unity install dir]/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Preprocess.js:91
return;
^^^^^^
SyntaxError: Illegal return statement
at Loader.moduleStrategy (internal/modules/esm/translators.js:88:18)
at async link (internal/modules/esm/module_job.js:41:21)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Building Builds\Web\Build\Web.loader.js failed with output:
(node:80608) ExperimentalWarning: The ESM module loader is experimental.
file:///[unity install dir]/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Preprocess.js:91
return;
^^^^^^
SyntaxError: Illegal return statement
at Loader.moduleStrategy (internal/modules/esm/translators.js:88:18)
at async link (internal/modules/esm/module_job.js:41:21)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Building Builds\Web\TemplateData\style.css failed with output:
(node:83572) ExperimentalWarning: The ESM module loader is experimental.
file:///[unity install dir]/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Preprocess.js:91
return;
^^^^^^
SyntaxError: Illegal return statement
at Loader.moduleStrategy (internal/modules/esm/translators.js:88:18)
at async link (internal/modules/esm/module_job.js:41:21)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
I've tried Googling it, but I couldn't find anything other than this post which didn't really help me at all.
- OS: Windows 11
- Unity version:
2022.3.4f1 - Node.JS version (I'm not sure if it really matters):
20.8.1
EDIT: I looked in "Preprocess.js" to see where the error was and it looks like it was here:
if (!locals.outputPath) {
console.log(JSON.stringify(Object.keys(locals.variables)));
return;
}
There's just a return in the global scope... Not sure if this has to do with anything but I thought it might be helpful
EDIT 2: I commented out the return statement:
file:///[unity install dir]/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Preprocess.js:2
fs: require("fs"),
^
ReferenceError: require is not defined
at file:///[unity install dir]/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Preprocess.js:2:7
at ModuleJob.run (internal/modules/esm/module_job.js:137:37)
at async Loader.import (internal/modules/esm/loader.js:179:24)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
```