discordx-ts / discordx

🤖 Create a discord bot with TypeScript and Decorators!
https://discordx.js.org
Apache License 2.0
607 stars 50 forks source link

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

Closed dl-tg closed 1 year ago

dl-tg commented 1 year ago

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

Satont commented 1 year ago

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

dl-tg commented 1 year ago

Thanks! Solved it.

DavidCodesDev commented 9 months ago

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

TeamWolfyta commented 9 months ago

@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. 😄

samarmeena commented 9 months ago

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