Description
When attempting to execute my code, I encountered an issue. I made several changes to my tsconfig in hopes of resolving it, but now I can't remember what modifications I made. Any insights on this matter would be greatly appreciated!
The package ts-node-dev is being used to run the code.
Main.ts
This is the primary TypeScript code that is executed first:
import { ShardingManager } from 'discord.js';
import { client } from '../config/config';
import chalk from 'chalk';
const manager = new ShardingManager(__dirname + '/client.ts', { token: client.token });
manager.on('shardCreate', (shard) => console.log(chalk.magenta(`[SHARD MANAGER]`), `Launched shard ${shard.id}`));
manager.spawn();
Client.ts
Here is the client.ts code that is managed by the sharding manager:
import { Client as DiscordClient, Intents } from 'discord.js';
import { client } from '../config/config';
const Client = new DiscordClient({ intents: [Intents.FLAGS.GUILDS] });
Client.on('interactionCreate', (interaction) => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'stats') {
return Client.shard
.fetchClientValues('guilds.cache.size')
.then((results) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return interaction.reply(`Server count: ${results.reduce((acc, guildCount) => acc + guildCount, 0)}`);
})
.catch(console.error);
}
});
Client.login(client.token);
Error
Below is the error message I am encountering:
/workspace/Hez/src/client/client.ts:1
import { Client as DiscordClient, Intents } from 'discord.js';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.nodeDevHook [as .js] (/workspace/Hez/node_modules/ts-node-dev/lib/hook.js:63:13)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/workspace/Hez/node_modules/ts-node-dev/lib/wrap.js:104:1)
[ERROR] 16:20:04 SyntaxError: Cannot use import statement outside a module
Package.json
{
"devDependencies": {
"@discordjs/builders": "^0.9.0",
"@discordjs/rest": "^0.2.0-canary.0",
"@types/express": "^4.17.13",
"@types/node": "^17.0.2",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"discord-api-types": "^0.25.2",
"discord.js": "^13.3.1",
"eslint": "^8.5.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"express": "^4.17.2",
"mongoose": "^6.1.2",
"prettier": "^2.5.1",
"ts-node": "^10.4.0",
"ts-node-dev": "^1.1.8",
"typescript": "^4.5.4"
},
"dependencies": {
"chalk": "4.1.2"
},
"name": "",
"description": "",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "none",
"start": "ts-node src/start.ts",
"dev": "ts-node-dev src/start.ts",
"watch": "npx tsc",
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
"lint": "eslint . --ext .ts"
}, "keywords": [],
"author": "",
"license": "ISC",
}