altmp / altv-js-module

JS module for alt:V Multiplayer. Powered by NodeJS & v8
MIT License
55 stars 35 forks source link

Unrelated error log #254

Closed mrgharabaghi closed 1 year ago

mrgharabaghi commented 1 year ago

Description of the problem

Using the await in the non-async callback function causes the below error on the server log.

SyntaxError: Unexpected reserved word
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:468:14)
[05:51:47][Error] Failed to load resource bennys

Reproduction steps

  1. Make a file like this in an example resource.
    
    import * as alt from 'alt-server';

setTimeout(() => { await new Promise((res) => { setTimeout(() => { console.log('Hello!!!'); res(); }, 1000); }); }, 0);

2. Run the server.
3. Error log appeared in the console.

SyntaxError: Unexpected reserved word at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18) at ESMLoader.moduleProvider (node:internal/modules/esm/loader:468:14) [05:51:47][Error] Failed to load resource bennys


### Expected behaviour

alt:V's `js-module` should generate logs like Node.js official error.
This is the normal error on Node.js console.

await new Promise((res) => { ^^^^^ SyntaxError: await is only valid in async functions and the top level bodies of modules



### Additional context

_No response_

### Operating system

Windows 10

### Version

dev/15.0-dev15

### Scope

server

### Reproduction tested

- [X] I confirm that I have made sure that this issue is also present on the newest dev version
LeonMrBonnie commented 1 year ago

With the current way we handle it, it's not fixable and we won't rewrite the whole bootstrapper anymore.