#Exit code 1 [SOLVED]
202 messages · Page 1 of 1 (latest)
- 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!
compile ur ts to js, then run it. By using tsc (typescript) and node
i did
didnt work
gonna need a bit more then "didnt work", show ss's, what did you run? What happens? What's ur code
i did show the screenshot
the code is just a discord bot
doesnt run
i console logged above the import
like the description says
i did a lot of tests
and nothing works
it works perfectly fine on windows
forgot to mention im on macos
that's also ts code, you don't really run ts
What's the content of ./Kuramisa file? I assume it's just creating a DiscordJS Client class
Why is this showing nodemon, when you ran tsx, not nodemon?
i use nodemon
yes
and i tried withput nodemon
like i said, i have tried tsc and running compiled code within dist same issue
exporting ur client doens't look very good either
Show your console doing node ./dist/index.js
its not a code problem tho
because the code doesnt even get executed
Why are you exporting from your index.ts? That is indeed a code problem
The only reason why you would do that is circular imports. Which are a problem
alright
ill remove default export
but like i said
it works on windows and linux
And does indeed cause node to silently exit from time to time
alright
ill try
And 👆
wait no
it wont cause circular imports
because im exporting an already initialized class
No. Not if something imported from ./Kuramisa tries to import it
so i want to access the initiated class everywhere
if i try export { kuramisa } same issue?
Yes
Don‘t export at all from your index. The only files that could import that are ones imported from index. Causing circular imports
so how do i make it so i can export kuramisa instance to access it from other files without causing circular imports
Pass it to those files as parameters. Or make a file that is not your index and define and export it there and import that file in your other files. But why realistically all your files that need it should already get it passed one way or another
hm
can u show me an example if u dont mind
Creating Your Bot: Event handling
read more
no parameters
like for example sapphire js provides a exported instance container that can access the client and everything already initialized anywhere without passing client around in parameters how do they do it?
what if i create a hook called useClient() which returns the client instance?
will that avoid circular imports?
for example within kuramisa client ill create a static method called useClient
nvm
static cant access this context
They Export the container from a file and then add properties to it from other files. All of those files import the container file
alright that makes sense
but can i also do what i suggested?
import Kuramisa from "./Kuramisa";
const kuramisa = new Kuramisa();
kuramisa.login();
export const useClient = () => kuramisa;
will this work instead?
Why though? It makes no sense to me. What kind of files are those that need to “get“ the client without already having access to it?
also you'll likely have a this.on(..., ...args) or something like that somewhere if you have an event handler, you can just pass ur client in there. Or just use the interaction(ect).client. If you're worried about types you can just make a
declare module "discord.js" {
interface Client {
}
}
i dont want to pass around client everywhere where it is needed for one time use
or upon creating certain classes when the bot is already initialized/ready
That’s rather vague. Name one specific use case
thank you for suggestion but i dont think thats relevant in this case
i mean that's literally what most people do, but you do you
What would the command need your client for? Considering it‘ll get called from interactionCreate event which (as gwapes stated) has a .client property on the interaction
i dont need to modift Client interface because i already have extended Client to its own class called Kuramisa
by editing the client class... all that does would just make your types available if using interaction.client
becuse i have extended my own client
We highly recommend you extend the Client structure properly instead of just attaching custom properties like .commands to the regular discord.js Client instance.
- Using typescript, you might want to consider casting or augmenting the module type
last link
thats what i did
interaction.client is ur extended client
You cast or augment the module type? Where?
interaction.client is ur extended client, by doing the declare module thing it means that interaction.client will be shown to ts as ur extended client. Meaning you don't have to do:
(interaction.client as Kuramisa)
Every time
wait so
maybe i misunderstood
interaction.client will hold all those valuse that i extended too?
djs basically puts the client everywhere
yes
Yes
Ohhhh
OHH
im sorry
my bad
message.client, reaction.client (?), interaction.client
ohh
i really didnt know that
that saves so much headaches
I pass it within my event/command handlers because i want to
fr
Neither does ts (know that). Which is why you need to tell it by casting or augmenting
yes that makes sense
but i didn't know about augmenting (declare module ...) for ages, which is why i passed it as a param, ...args, client
Alright ill try doing that
and then
reach back
I also didn't know that circular imports would just cause node to "crash" entirely and not give an error so that's nice to know
overloading prolly and gets lost
Neither did I know a week ago… that’s why I now do
Was a long day for me to find that issue
good job you found out 😂 educating all of us lol
oh...
One more question
oui
will this cause a circular import?
im importing just the class
not the created instance of th e class
Not too sure on that one. I believe if you don't start the client in that file it's fine
Like if you just define it there, then use it inside ur index.ts/js it's fine
As that's what I do and it's fine
I have a Classes/CustomClient/CustomClient.ts file and the import it into /index.ts and use it there
So that way i can use it as a type in other files by importing it from Classes/CustomClient/CustomClient.ts
no i mean like
i wanna pass the client around
should i instead do import type?
cuz im not using the Kuramisa itself but the one that is being passed in a constructor
I'm not 100% on it but what i said should be fine
No i agree with you but since qjuh mentioned circular importing now im paranoid lol
.
Yes i understand but im using typescript
so i need to import types
Then you’ll follow what I said and what Qjuh just said
Importing types get stripped on transpilation. So not circular
yes, i figued that out and i completely refactored my structure working on few things right now, ill update the thread when i try it on my mac
Same problem
I tried on macos
im still running into the issue
I’m not too sure if there’s a way to debug circular imports but that’ll likely be the culprit
i spent around 6-7 hours of recoding the framework
its not circular imports
cuz i installed a eslint plugin that detects it
and im not getting any errors
Try and reinstall node? What’s ur version?
You can node —inspect as well which’ll give you an inspect thingy
That’s two - iOS being fun
i did do that too :< i did it from scratch matter of fact
and i tried --inspect too
Ah
What’s ur version
And what actually happens? Does it just never log anything? What command do you use to start again and then show the file you start it with
22.14.0
no matter what command i use it crashes, i tried tsx, ts-node, node, bun
“Crashes” with an error? Or it just doesn’t do anything
And don’t use ts-node, you compile the ts and run the js. Always. Bun is known to be a little finicky when it comes to running stuff
I also suggest deleting ur entire dist and recompiling
since its Exit code 1 it means its a crash
i did that too
. End bot
Bit
yes i did the en dbit
and i did other stuff u mentioned too
?
You didn’t show
found it
i attached a debeugger
instaed of shitty --inspect
never threw an error
Can u show the file you run
And what you do to run the bot
yep that fixed it
That’s all that’s there?
in index.ts yes
And I’m guessing you then run dist/index.js
Do you happen to have an uncaughtException handler?
That blindly ignores the exception and does process.exit(1)
i do
but sadly uncaught exception handler happens
when the bot initialized
but in the past i have tried manually doing "process.on" in the index file
it never went thru
yes
Huh?
"but sadly uncaught exception handler happens when the bot initialized"
You really shouldn’t
hm? why
UncaughtExceptions are meant to crash your bot. And even more importantly: shown to you what exception was thrown
oh you said it
nvm,
fair point i agree
but i would like to keep unhandledRejection for now
so if i miss a rejecction i can fix it without the bot crashing
Or just remove it atm to find out what’s happening
And add breakpoint logs
Most of this is standard debugging which imo you should really already be doing
i did remove it
and its working
and fixed something
I have checkes throughout the app where if a env var is missing it will throw an error but even removing uncaughtException handler didnt fix it
so i just did this
Great