I got this error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/my-project/dist/structs/Handler imported from /my-project/dist/handlers/CommandHandler.js
I now it is because imports for JS need the .js extension but it is written in TS and compiled to JS.
I either need to solve this error OR find a way to run TS natively (without compiling to JS)
My files:
// Path to file: src/handlers/CommandHandler.ts
import Handler from "../structs/Handler";
export default class CommandHandler extends Handler {
constructor() {
super();
}
}
const test = new CommandHandler();
// Path to file: src/structs/Handler.ts
import { dirname } from 'path';
export default class Handler {
constructor() {
console.log("handler test")
}
}
script: tsc && node ./dist/handlers/CommandHandler.js
tsconfig.json:
{
"compilerOptions": {
"target": "ES6",
"module": "ES2022",
"outDir": "dist",
"rootDir": "src",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"moduleResolution": "node",
}
}