ShardingManager doesnt work with .ts files

I am trying to make a discord bot with typescript that uses shards, however the sharding manager crashes when I pass in a ts file like so:
const manager = new ShardingManager("./src/bot.ts", {
totalShards: "auto",
token,
});
const manager = new ShardingManager("./src/bot.ts", {
totalShards: "auto",
token,
});
here is my tsconfig:
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"outDir": "dist",
"sourceMap": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"importHelpers": true
},
"include": ["src", "environment.d.ts"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"outDir": "dist",
"sourceMap": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"importHelpers": true
},
"include": ["src", "environment.d.ts"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Is there any way to get this to work?
8 Replies
d.js toolkit
d.js toolkit12mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
KevinWho
KevinWho12mo ago
discord.js@14.11.0 node version: v18.14.0
space
space12mo ago
You want to refer to the javascript file in your dist folder there, as that's what node can work with.
KevinWho
KevinWho12mo ago
What do you mean? ohh ok, but that means I need to compile it every time Is there some way I can make it autocompile before getting there?
space
space12mo ago
I don't think you can, but you are already transpiling your sharding manager file, aren't you? You can pass the --watch flag to tsc to automatically retranspile when changes are detected. https://www.typescriptlang.org/docs/handbook/compiler-options.html
KevinWho
KevinWho12mo ago
hmm alright, I mean im using nodemon, it would be good if I could hook just add this on
space
space12mo ago
I'm not sure how that would work in combination, but maybe you can let it watch the dist folder, which tsc writes into? jynEHEH
KevinWho
KevinWho12mo ago
hmm ok ill keep looking, not sure, I moved to tsc-watch and ended up with this:
const manager = new ShardingManager("./dist/bot.js", {
totalShards: in_beta_test_mode ? 1 : "auto",
token,
});
const manager = new ShardingManager("./dist/bot.js", {
totalShards: in_beta_test_mode ? 1 : "auto",
token,
});
and
"dev": "tsc-watch --onSuccess \"node dist/index.js\""
"dev": "tsc-watch --onSuccess \"node dist/index.js\""
so it just compiles it, then runs it.
Want results from more Discord servers?
Add your server
More Posts