Compile Unity jslib in command
(Jin Qing’s Column, May., 2023)
My Unity project has a jslib file, which has many syntax errors.
But Unity does not report these jslib errors like cs files, until the WebGL build fails with a error like this:
Failed process stderr log:
error: failure to execute js library "E:\Test\Unity\My project (1)\Assets\Plugins\without_a_bundler.jslib": SyntaxError: Unexpected token import,,SyntaxError: Unexpected token import
...
at run (bootstrap_node.js:394:7)
preprocessed source (you can run a js engine on this to get a clearer error message sometimes):
=============
let wasm;
...
lib = {
...
};
mergeInto(LibraryManager.library, lib);
=============
Internal compiler error in src/compiler.js! Please raise a bug report at https://github.com/kripken/emscripten/issues/ with a log of the build and the input files used to run. Exception message: "SyntaxError: Unexpected token import" | SyntaxError: Unexpected token import
...
Traceback (most recent call last):
...
File "C:\Program Files\Unity\Hub\Editor\2020.3.26f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\tools\jsrun.py", line 132, in run_js
raise Exception('Expected the command ' + str(command) + ' to finish with return code ' + str(assert_returncode) + ', but it returned with code ' + str(proc.returncode) + ' instead! Output: ' + str(ret)[:error_limit])
Exception: Expected the command ['C:/Program Files/Unity/Hub/.../Editor/Data\\Tools\\nodejs\\node.exe', '--stack_size=8192', '--max-old-space-size=4096', ..., 'E:\\Test\\Unity\\My project (1)\\Assets\\Plugins\\without_a_bundler.jslib', ...] to finish with return code 0, but it returned with code 1 instead! Output: // The Module object: Our interface to the outside world. We import
...
It is hard to locate the error from the message, and the WebGL building takes a long time as well.
Try to run the command, which is hinted in the message:
"C:/Program Files/Unity/Hub/.../Editor/Data\\Tools\\nodejs\\node.exe" ^
--stack_size=8192 --max-old-space-size=4096 ^
"E:\\Test\\Unity\\My project (1)\\Assets\\Plugins\\without_a_bundler.jslib"
Ouput:
E:\Test\Unity\My project (1)\Assets\Plugins\without_a_bundler.jslib:205
input = new URL('without_a_bundler_bg.wasm', import.meta.url);
^^^^^^
SyntaxError: Unexpected token import
...
It is a quick way to using nodejs to check the jslib file.
When all errors are fixed, the result output should be like:
E:\Test\Unity\My project (1)\Assets\Plugins\without_a_bundler.jslib:226
mergeInto(LibraryManager.library, lib);
^
ReferenceError: mergeInto is not defined
...