I am trying to write a very simple Typescript project but it does not seems to work. Here's my project structure
(including also the dist folder):
├── dist
│ ├── hello.js
│ └── index.js
├── package-lock.json
├── package.json
├── src
│ ├── hello.ts
│ └── index.ts
└── tsconfig.json
my hello.ts:
export function sayHello() {
console.log("Hello");
}
my index.ts:
import { sayHello } from "./hello";
sayHello();
my tsconfig.json:
{
"compilerOptions": {
"rootDirs": ["src"],
"outDir": "dist",
"lib": ["es2020"],
"target": "es2020",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"types": ["node"]
}
}
my package.json:
{
"name": "ts-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile": "tsc",
"start": "npm run compile && node ./dist/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"devDependencies": {
"@types/node": "^20.4.9",
"typescript": "^5.1.6"
}
}
The error I am getting is:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '****/ts-test/dist/hello' imported from ****/ts-test/dist/index.js
What am I missing?