Gamelift.js Invalid or unexpected token


I have managed to get a gamelift fleet up and running (via cli) which has moved to active. However on the events it states “Server process is unable to start. This may be due to a problem with either the Realtime script or the runtime configuration launch path., launchPath(/local/NodeJS/bin/node), arguments(-- /local/game/src/gamelift.js --script …/…/…/local/game/etag-c9e18c3171490a131631193bebadd174/GladiatorArenaA.x86_64), instanceId(i-0cfdb781d40c1b93b), publicIP(, gameSessionId(none)” Several times.

I investigated further and managed to get into some gamelft logs. There are many instances of the logs (presumably where it has tried to startup and failed). Each instance states the same thing:
“28 Aug 2020 04:35:08,314 [INFO] (rt-logger.js) 59: Game session (PID: 1710) configured with logger: {“logDirPath”:”/local/game/logs/1710",“logLevelFilter”:"*.info",“filename”:“server.log”}
28 Aug 2020 04:35:08,476 [INFO] (index.js) 123: Game server was constructed with {“test_dist”:false,“script”:"…/…/…/local/game/etag-c9e18c3171490a131631193bebadd174/GladiatorArenaA.x86_64",“port”:1900,“end”:2000,“udp_port”:33400,“udp_port_end”:33500,“devargs”:null,“enable_security”:false}
28 Aug 2020 04:35:08,476 [INFO] (gamelift.js) 195: Starting GameLift Realtime server process. PID: 1710…
28 Aug 2020 04:35:08,477 [INFO] (gamelift.js) 200: Calling GameLiftServerAPI.SdkVersion…
28 Aug 2020 04:35:08,477 [INFO] (gamelift.js) 205: GameLiftServerAPI.SdkVersion succeeded with result: 3.3.0
28 Aug 2020 04:35:08,477 [INFO] (gamelift.js) 208: Calling GameLiftServerAPI.InitSDK…
28 Aug 2020 04:35:08,495 [INFO] (gamelift.js) 213: GameLiftServerAPI.InitSDK succeeded
28 Aug 2020 04:35:08,495 [INFO] (gamelift.js) 216: Waiting for Realtime server to start…
28 Aug 2020 04:35:08,496 [INFO] (index.js) 149: Loading game server script at path: /local/game/etag-c9e18c3171490a131631193bebadd174/GladiatorArenaA.x86_64
28 Aug 2020 04:35:08,496 [FATAL] (gamelift.js) 189: Realtime server crashed due to: process.unhandledRejection – See stacktrace for more details:
(function (exports, require, module, __filename, __dirname) { ELF

SyntaxError: Invalid or unexpected token
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)"

Presumably this means that there is some sort of error with this section which is being parsed. However, I struggle to see how this is anything to do with my naming - which I am really careful about and use only standard casing (not even any numbers).

Please can someone let me know if there is a way I can dig further or if you know anything about this error?

If you provide the fleet and region, I can ask the GameLift service team to look.

Not a Node expert, but failures in the cjs loader need to be tracked down to what its trying to load. I would look at your changes to gamelift.js and see what you added. Ensure the file is valid NodeJS.

This could be as simple as checking the encoding is valid for the script as a common source of these errors are stray BOM marks and other ‘invisible’ chars that crept in during copy-n-paste operations etc. Any IDE that supports NodeJS or even things like notepad++ can help you here.

For Realtime I would always advise getting the simplest working script running first and then building on that. Good luck.

Hi @Pip

I have taken a look at the script params and they all seem to be valid as far as I can tell, the only params I can see is the name of the file as the gamelift.js is an automated script on amazons side?

The region is ap-southeast2 and the fleet is fleet-ff4450ed-5be1-4ea8-88fb-ff479e463bed

If someone could take a quick look I would really appreciate it!


I’ve pinged the GameLift service team to take a look. Hopefully they will have a response soon.

While you are waiting you could try and debug this yourself.

Are you just running a standard Realtime server script from the examples? If you have modifications you may want to start from the example script and slowly make changes from there.

I would still suggest checking the encoding of the script files themselves and that something validates them as valid NodeJS files. It was unclear from your response if you’ve done that.

Sorry for the delay in response.

Looking at the logs we have and it looks like the script process is unhealthy. This checks out with the exception you are seeing.

It also looks like there might be a syntax error in the script that you are using. I’m wondering if the stacktrace is trying to say there’s a extra ‘(’. Would it be possible to get a copy of the script or just the code around
‘(function (exports, require, module, __filename, __dirname) { ELF’?

Hi @Kenneth,
Thanks for replying no worries about the delay!

I got as far to see the line ‘(function (exports, require, module, __filename, __dirname) { ELF’? but on console the two characters before ELF are some sort of non ascii character (not sure if that could be a problem too?).
However, I have exported the file straight from Unity so I am unsure what bit exactly contains the function described. I know that it is nothing I have written for sure!
I have a feeling that it might be some sort of auto generated function?

These are the parameters I am using for the gamelift script:

I was trying to do some debugging myself but it is difficult as i’m not sure where the problem originates? It all runs fine on gamelift local!



I have a suspicion that the uploaded script isn’t a javascript but instead is an executable binary.

Loading game server script at path: /local/game/etag-c9e18c3171490a131631193bebadd174/GladiatorArenaA.x86_64 - the .x86_64 file extension suggests this is a Linux executable not a javascript file.

This might be the cause of the problem because we use nodejs’s vm.Script to load a javascript file to be run. If the file isn’t javascript, this might be why there’s a Syntax error as it can’t be compiled as such.

Did you load a javascript file into your s3? If so, could you provide the contents so that I can debug further?

Hi @Kenneth and @Pip,

The solution is exactly in the wording - script!

What I intended to do was upload the zip as a build, but what somehow happened was that I uploaded the build as a script!

I am very grateful that you looked into this and I am sorry for wasting your time!