JS require is broken

General guideline is: if you ‘need help’, do not post here. Post in the right support section instead.

WARNING: THIS IS NOT A HELP SECTION

If you post here without knowing what you’re doing you’ll most likely get suspended. You should probably instead post in:


For a good bug report you should probably include:

  1. Client (production/canary) and FXServer version
    canary with 3922 FXServer version
  2. What you expected to happen
    expected scripts to be required
  3. What actually happens
    image
  4. Category of bug (eg. client, server, weapons, peds, native)
    server i believe
  5. Reproducible steps, preferably with example script(s)
    make 2 files and require secondary file inside primary one

i believe that happens because of fivem’s node implementation with its “dummy.js” file being created.
Its impossible to require files inside other files because fivem’s node executes server_script inside dummy-js, which is “located” in the root of the resource folder, and if server_script is not inside root_folder, it cannot find any scripts that are required.
heres 2 repos GitHub - lurkmorr/fivem-js-require-error
one is working well, but another one’s execution is failed due to this kind of error
GitHub - lurkmorr/fivem-js-require-error

there’s a workaround i found, but it seems not to good
create index.js file inside the root folder and mark it as server_script inside fxmanifest.lua.
and type just one line inside this file
require('./dist/index')
but it seems stupid, hope this bug will be fixed
[UPD]
added third resource to the repo with “stupid” implementation

I don’t think this can be fixed without deferring execution of all server-side JS to the Module._compile API, which involves a lot of reliability/compatibility risks for no real good reason since this can be trivially worked around by placing a root module in the root folder or using webpack. :confused: