heroiclabs / nakama

Distributed server for social and realtime games and apps.
https://heroiclabs.com
Apache License 2.0
8.85k stars 1.08k forks source link

Failed to eval JavaScript modules - TypeError #727

Closed cwcb closed 2 years ago

cwcb commented 2 years ago

Description

JavaScript TypeError when starting up Nakama 3.9.

When using exact same code below in 3.8 there are no errors.

An example of the code that appears to fail to Initialise is:

var __extends = undefined && undefined.__extends || function () {
  var extendStatics = function extendStatics(d, b) {
    extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function (d, b) {
      d.__proto__ = b;
    } || function (d, b) {
      for (var p in b) {
        if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
      }
    };

    return extendStatics(d, b);
  };

  return function (d, b) {
    if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
    extendStatics(d, b);

    function __() {
      this.constructor = d;
    }

    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();

var Test = function () {
  function Test(name, data) {
    this.name = name;
    this.data = data;
  }

  return Test;
}();

var Extender = function (_super) {
  __extends(Extender, _super);

  function Extender(name) {
    return _super.call(this, name, "data") || this;
  }

  return Extender;
}(Test);

function InitModule(ctx, logger, nk, initializer) {
  logger.info("Hello World!");

}

!InitModule && InitModule.bind(null);

Steps to Reproduce

  1. Use provided code as index.js.
  2. Start Nakama

Expected Result

No error is thrown and results are returned by server.

Actual Result

{"level":"error","ts":"2021-11-30T14:14:03.199Z","caller":"server/runtime_javascript.go:1521","msg":"Failed to eval JavaScript modules.","error":"TypeError: Assignment to constant variable. at extendStatics (index.js:3:21(18))"}
{"level":"error","ts":"2021-11-30T14:14:03.199Z","caller":"server/runtime.go:597","msg":"Error initialising JavaScript runtime provider","error":"TypeError: Assignment to constant variable. at extendStatics (index.js:3:21(18))"}
{"level":"fatal","ts":"2021-11-30T14:14:03.199Z","caller":"v3/main.go:146","msg":"Failed initializing runtime modules","error":"TypeError: Assignment to constant variable. at extendStatics (index.js:3:21(18))"}

Your Environment

cwcb commented 2 years ago

UPDATE:

This issue is still happening in v3.10.0.

Also, I identified the specific commit where this issue started taking place: de3ef8866ac97c7234f82ef739e3195bf8e67bc8

sesposito commented 2 years ago

Thanks for the report @cwcb, could you please provide the non-transpiled code snipped as well?

cwcb commented 2 years ago

@sesposito I think it is safe to close this. I realised when I was getting the non-transpiled version of the code that we have a custom process that is run on the js before it is rolled up. This custom process was what was causing the issue. When transpiling normally no issue occurs. Thank you for looking into this though!