🥹😍 Không hiểu tại sao khi sử dụng nodemon.json nó mới chạy được?
Nhận thấy khi thêm cấu hình --file nó mới chạy
package.json
{
"scripts": {
"dev": "ts-node --files ./src/index.ts"
},
"dependencies": {
"@types/node": "^22.13.4",
"@types/typescript": "^2.0.0",
"nodemon": "^3.1.9",
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
}
}
Còn không bạn phải cấu hình file nodemon.json như sau
{
"watch": ["src"],
"ext": ".ts,.js",
"ignore": [],
"exec": "ts-node --files ./src/index.ts"
}
package.json
{
"scripts": {
"dev": "ts-node --files ./src/index.ts"
},
"dependencies": {
"@types/node": "^22.13.4",
"@types/typescript": "^2.0.0",
"nodemon": "^3.1.9",
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
}
}
src\index.ts
global.example = 'hello world';
global.sum = function (a: number, b: number) {
return a + b;
};
console.log(global.example); // 👉️ "hello world"
console.log(global.sum(15, 25)); // 👉️ 40
src\types\index.d.ts
declare global {
var example: string;
function sum(a: number, b: number): number;
}
export {};

Hoặc

src\index.ts
global.example = 'hello world';
global.sum = function (a: number, b: number) {
return a + b;
};
console.log(global.example); // 👉️ "hello world"
console.log(global.sum(15, 25)); // 👉️ 40
console.log(example); // 👉️ "hello world"
console.log(sum(15, 25)); // 👉️ 40
Hoặc ta có thể ném index.d.ts ra khỏi thư mục nó vẫn hoạt động ok

Nếu ném nó vào thư mục src nó báo lỗi

Nhận thấy khi đổi tên thành abc.d.ts nó vân hoạt động tốt ở ngoài lẫn ở trong types hoặc thư mục test cũng ok


PreviousMini Website with TypeScript, compile file ts chạy thời gian thực (ok)NextMini Website with TypeScript, html, .d.ts, cấu hình nodemon.json (ok)
Last updated