ReferenceError: exports is not defined in ES module scope
I am trying to run my bot and am presented with the following error
What do I need to do to resolve this?
Since there are so many files involved and the length would exceed the Discord limitations, I created a gist with everything I think is needed.
https://gist.github.com/dustin-lennon/30bee1b477e4de8dae3459f4fa4c6b96
What do I need to do to resolve this?
Since there are so many files involved and the length would exceed the Discord limitations, I created a gist with everything I think is needed.
https://gist.github.com/dustin-lennon/30bee1b477e4de8dae3459f4fa4c6b96
Gist
ReferenceError: exports is not defined in ES module scope - TraktClient.ts

Solution
so when using pnpm you need to hoist all of
As for your root cause, it really comes down to how you configured tsconfig. The modern standard is to use
Once that is done and you compile with either exclusively swc (which you seem to use yet you also mention ts-node, they DO NOT work together, also we discussed the downsides of ts-node) or alternatives such as
The error in particular suggests that you compiled for CJS but are running as ESM (i.e. you specified
@sapphire/* because otherwise TS cannot properly resolve module augmentations. I forgot the exact option but it's one of the hoist pattern options. As for your root cause, it really comes down to how you configured tsconfig. The modern standard is to use
node16 for both module and moduleResolution then either use "type": "commonjs" or "type": "module" in your package.json based on whether you respectively want a CJS or ESM runtime. Once that is done and you compile with either exclusively swc (which you seem to use yet you also mention ts-node, they DO NOT work together, also we discussed the downsides of ts-node) or alternatives such as
tsc / tsc-watch / tsup.The error in particular suggests that you compiled for CJS but are running as ESM (i.e. you specified
"type": "module" in your package.json) which causes the error of exports not being defined in an ES module (ESM) scope. So either change your compilation to ESM, or change "type": "module" to "type": "commonjs.