Exports in javasript using webpack does not work

Hi all,

I started to code my old lua scripts in ( javascript /typescript ) using webpack
I’m exporting some functions following the example in the documentation

https://docs.fivem.net/docs/scripting-reference/runtimes/javascript/functions/exports/

This is an example: script.js

exports("sayHello", (text) => {
    console.log(text)
})

When i run the script and open the game console i see this error:
TypeError: exports is not a function

I assume it’s trying to use the exports variable from nodejs or webpack env not the one from fivem core

Can anyone help me with this issue?
Thank you !

Did you ever find a solution to this? I’m running into it as well.

When using webpack, use globalThis.exports.

You can use global.exports.resource_name.method_name

In order to use exports in Javascript you need to use globalThis.exports.
If you have @types/node installed, then you can just use global.exports.

And also for the @citizen/* packages not to clash with @types/node you need to have the skipLibCheck directive set to true in your tsconfig.json.