- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
#I am new to Typescript and I am trying to convert my Js code to ts
23 messages · Page 1 of 1 (latest)
Show your errors you get
Either use require and commonjs. Or use import and esm. Don’t mix them both
can do it with bun js
Show your functions/handleEvents.ts file. It doesn’t seem to export a function but you try to use it as one
Yeah, that uses esm exports so you can’t call it with require
import handleEvents from '…' and then do handleEvents(client)🤷♂️
You do the import at the top, like any other import. And then you just call the function where you currently require and call it in the same line
What mistake? How did you come to that conclusion? You might want to await the handleEvents call
Yes. What node version do you intend to run this on?
No, v20 is fine. But in that case you can use es2022 target without issue, even es2024 is mostly supported in it
Why is there both .js and .ts in your src folders? You should locate the folder you transpile too outside the src folder and you should put the relative paths for your ts files. tsc will take care of adjusting them accordingly
Where’s the bot.ts that transpiles to that bot.js you have in test directory? It looks like you coded that in js directly?
Then why do you have a bot.js that‘s in your test folder and not its Utils subfolder?
No. You shouldn’t put any .js file manually anywhere. Make only .ts files. even for your main file, be it src/index.ts or src/bot.ts whatever you call your main file you run
And why is your test folder (which tbh would be better named as dist or build or whatever) now inside your src/Utils folder 
You write only ts in src folder. You run only js in dist folder
Where do you have endsWith ts? In your command/event loader? You should have endsWith js there, because during runtime your files will all be js