Typescript compiler bug

Hi, I’ve came across some wierd error with typescript compilation and maybe you can help me out.

So i have my client file (src/client/main.ts) which looks like this:

const Core = exports["core"].getSharedObject();

console.log(`My job is: ${Core.PlayerData.job.name}`);

which compiles into (dist/client/main.js):

(() => {
  var __getOwnPropNames = Object.getOwnPropertyNames;
  var __commonJS = (cb, mod) => function __require() {
    return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  };

  var require_main = __commonJS({
    "src/client/main.ts"(exports) {
      var Core = exports["core"].getSharedObject();
      console.log(`My job is: ${Core.PlayerData.job.name}`);
    }
  });
  require_main();
})();

and throws error:

[    525921] [b2944_GTAProce]             MainThrd/ Error loading script dist/client/main.js in resource assynu-typescript: TypeError: Cannot read properties of undefined (reading 'getSharedObject')
[    525921] [b2944_GTAProce]             MainThrd/ stack:
[    525921] [b2944_GTAProce]             MainThrd/ TypeError: Cannot read properties of undefined (reading 'getSharedObject')
[    525921] [b2944_GTAProce]             MainThrd/     at src/client/main.ts (@assynu-typescript/dist/client/main.js:10:34)
[    525921] [b2944_GTAProce]             MainThrd/     at __require (@assynu-typescript/dist/client/main.js:4:52)
[    525937] [b2944_GTAProce]             MainThrd/     at @assynu-typescript/dist/client/main.js:14:3
[    525937] [b2944_GTAProce]             MainThrd/     at @assynu-typescript/dist/client/main.js:15:3
[    525937] [b2944_GTAProce]             MainThrd/ Failed to load script dist/client/main.js.
[    525937] [b2944_GTAProce]             MainThrd/ OnConnectionProgress: Mounted assynu-typescript (1 of 1)

but when i just edit the js file maunally to just use exports without that additional logic:

(() => {
  var Core = exports["core"].getSharedObject();
  console.log(`My job is: ${Core.PlayerData.job.name}`);
})();

it works fine. I think maybe during compilation exports function is overriden by some other node function? I have no idea what to do and i really need to use client side exports to get core functions which are written in lua so if anyone knows how can i fix that please help.

Also, on server side exports compiles fine, it’s just the client where it’s the issue

to fix it, use global.exports

1 Like

Along side this, does it work if you set your EcmaScript version higher? Not sure what transpiler you’re using, but “es2020” with esbuild is what we use for mostly everything.

I’m actually using ES2021, but also tried with 2020 and result was still same.

Using es2020 and targeting Node16. I’m getting the same. Need to use global this, or just global if referencing @anon8295134/node.