Build Error with ts-node

Hi, I'm using typescript and I'm getting a strange error that isn't actually in my file!
Error:
Failed to import from:
/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/commands/alerts/alerts.ts.
Options:
{}
Require error message:
TSError: ⨯ Unable to compile TypeScript:
src/commands/alerts/functions.ts:2:32 - error TS2532: Object is possibly 'undefined'.

2 var __importDefault = (this && this.__importDefault) || function (mod) {
~~~~

at createTSError (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1433:41)
at Object.m._compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1617:30)
at Object.m._compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
at require.extensions.<computed> (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1621:12)
at Object.require.extensions.<computed> [as .ts] (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1621:12)
at /Users/marlon/Javascript/ce-discord-bot/node_modules/esm/esm.js:1:251778

at esmImport (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/import-sync/src/import.ts:48:11)
at importSync (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/import-sync/src/import.ts:70:26)
at scanDirectory (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:38:46)
at scanDirectory (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:34:17)
at scanCommands (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:55:5)
at getCommandObjects (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:61:26)
at deployCommands (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:87:22)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/index.ts:36:5)
Error:
Failed to import from:
/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/commands/alerts/alerts.ts.
Options:
{}
Require error message:
TSError: ⨯ Unable to compile TypeScript:
src/commands/alerts/functions.ts:2:32 - error TS2532: Object is possibly 'undefined'.

2 var __importDefault = (this && this.__importDefault) || function (mod) {
~~~~

at createTSError (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1433:41)
at Object.m._compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1617:30)
at Object.m._compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
at require.extensions.<computed> (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1621:12)
at Object.require.extensions.<computed> [as .ts] (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1621:12)
at /Users/marlon/Javascript/ce-discord-bot/node_modules/esm/esm.js:1:251778

at esmImport (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/import-sync/src/import.ts:48:11)
at importSync (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/import-sync/src/import.ts:70:26)
at scanDirectory (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:38:46)
at scanDirectory (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:34:17)
at scanCommands (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:55:5)
at getCommandObjects (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:61:26)
at deployCommands (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:87:22)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/index.ts:36:5)
The code in question: https://srcb.in/HRuwOaDSwE To load this file, i'm using the "import-sync" module.
const module = importSync(filePath)
const module = importSync(filePath)
SourceBin
functions.ts
Instantly share your code with the world.
9 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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! - Marked as resolved by staff
Ori
OriOP12mo ago
I know, I only use it for developping. Using tsc works fine. Only ts-node is having this error Oh that exists?
table
table12mo ago
use deno if you want to write your bot in ts, it's easier + you don't have to configure any tsconfig.json, and there isn't any double storage thing with src/build folders
Ori
OriOP12mo ago
Sadly I’ve already coded my whole template with typescript in nodejs… Will this auto refresh the files when saved?
table
table12mo ago
it shouldn't be that hard to convert you just install deno i think and then delete your tsconfig.json and the /build directory then deno run index.ts in cmd and u should be good to go that's what i did
Ori
OriOP12mo ago
What are the other advantages of demo
table
table12mo ago
idk just free ts only downside is that intellisense is hella slow
Ori
OriOP12mo ago
@Qjuh I've been trying to follow your advice and run the compiled code instead of using ts-node. But i can't manage to make it so my other non-ts files are added to the build (images, config files, etc) I never used the build because I never deployed to production. I was testing on my machine with ts-node So like do I put my images, config, etc outside of src?
Rajaneesh R
Rajaneesh R12mo ago
bruh just use a loader node --no-warnings --loader ts-node/esm src/index.ts
Want results from more Discord servers?
Add your server