discordx-ts / discordx

🤖 Create a discord bot with TypeScript and Decorators!

Home Page:https://discordx.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

dl-tg opened this issue · comments

commented

What happened?

run main.ts using ts-node;

Reproduction

ts-node main.ts

tsconfig.json: `{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"outDir": "build",
"rootDir": "src",
"strict": true,
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,

"experimentalDecorators": true,
"emitDecoratorMetadata": true,

"skipLibCheck": true,
"forceConsistentCasingInFileNames": true

},
"exclude": ["build", "node_modules"],
"type": "module",
}`

Package

discordx

Version

Stable

Relevant log output

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\projs\ts\fetchbot\fetchbot\src\main.ts
    at new NodeError (node:internal/errors:387:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:76:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:118:38)
    at defaultLoad (node:internal/modules/esm/load:81:20)
    at nextLoad (node:internal/modules/esm/loader:165:28)
    at ESMLoader.load (node:internal/modules/esm/loader:608:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:464:22)
    at new ModuleJob (node:internal/modules/esm/module_job:63:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:483:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:441:34) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

Code of Conduct

  • I agree to follow this project's Code of Conduct

Did you tried ts-node --esm src/main.ts?

commented

Thanks! Solved it.

This is still an issue for me, with a fresh install with the npx command

@CodeStarrk Just to note, If you're running the latest node version (v20), ts-node has still not been updated to run on it. You may have to either go back to using node v18, Have a script clean, compile and then build using typescript or find a different runtime engine similar to ts-node.

If it is the fact you're using node version 20 most people have been swapping to use something called tsx however tsx does not support emitDecoratorMetadata which I do believe is something that Discordx NEEDS to have enabled. There are other runtime engines but haven't played around with them, If you find something that works please post it here, It would be very helpful. 😄

yeah thanks, I am aware about this. will update in templates as well.