I should clarify, I wasn’t too sure on the most appropriate sub-forum for this post, here goes anyhow.
@types/node declares the global variable exports as well and a conflict arises when using both declarations.
$ tsc node_modules/@types/node/index.d.ts:289:13 - error TS2451: Cannot redeclare block-scoped variable 'exports'. 289 declare var exports: any; ~~~~~~~ ../typings/fivem.d.ts:80:15 80 declare const exports: any; ~~~~~~~ 'exports' was also declared here. ../typings/fivem.d.ts:80:15 - error TS2451: Cannot redeclare block-scoped variable 'exports'. 80 declare const exports: any; ~~~~~~~ node_modules/@types/node/index.d.ts:289:13 289 declare var exports: any; ~~~~~~~ 'exports' was also declared here. Found 2 errors.
Of course, the obvious fix is to remove the second exports declaration from FiveM’s declaration file in my development environment, however, I know that FiveM installs some magic in the exports global but I don’t necessarily believe that this is best practice in the first place.
As an intermediary fix, can I suggest that CitizenFX change the declaration for exports in their type declaration file to be:
declare var exports: any;
so that it is compatible with @types/node’s declaration?
I would actually like to initialise a discussion around whether overriding the exports global is best practice and how CitizenFX currently has the opportunity to change this practice before the JS resource scene explodes. Can I propose that maybe another unused global is used or that there is better integration implemented into FiveM/FiveM’s Node.js fork with FiveM resources and Node.js modules?