-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathloader.mjs
More file actions
34 lines (30 loc) · 1014 Bytes
/
loader.mjs
File metadata and controls
34 lines (30 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// TypeScript ESM loader for ts-node
import { register } from "node:module";
import { pathToFileURL } from "node:url";
import { config } from "dotenv";
// Set up error handlers BEFORE loading any modules
process.on('uncaughtException', (error) => {
console.error('\n💥 Uncaught Exception During Module Loading:');
console.error('Error:', error);
console.error('Message:', error.message);
console.error('Stack:', error.stack);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('\n💥 Unhandled Promise Rejection:');
console.error('Reason:', reason);
if (reason instanceof Error) {
console.error('Stack:', reason.stack);
}
process.exit(1);
});
// Load environment variables before any TypeScript modules are loaded
config();
// Register ts-node with error handling
try {
register("ts-node/esm", pathToFileURL("./"));
} catch (error) {
console.error('\n💥 Failed to register ts-node loader:');
console.error(error);
process.exit(1);
}