Skip to content

Commit 124e721

Browse files
committed
fix: prevent Sentry module loading entirely during test execution
- Move Sentry import to conditional dynamic import in main entry point - Prevents module loading conflicts that cause 'module is already linked' errors - Uses comprehensive test environment detection for all CI systems - Ensures tests run without any Sentry initialization or module conflicts
1 parent 4bfa785 commit 124e721

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,22 @@
1313
* - Handling server lifecycle events
1414
*/
1515

16-
// Import Sentry instrumentation
17-
import './utils/sentry.js';
16+
// Import Sentry instrumentation only if not in test environment
17+
const isTestEnvironment =
18+
process.env.NODE_ENV === 'test' ||
19+
process.env.VITEST === 'true' ||
20+
process.env.CI === 'true' ||
21+
process.env.GITHUB_ACTIONS === 'true' ||
22+
process.argv.some((arg) => arg.includes('vitest')) ||
23+
(typeof global !== 'undefined' && 'vitest' in global) ||
24+
(typeof process !== 'undefined' && process.env.npm_lifecycle_event === 'test');
25+
26+
// Initialize Sentry asynchronously only in production environments
27+
if (!isTestEnvironment) {
28+
(async (): Promise<void> => {
29+
await import('./utils/sentry.js');
30+
})();
31+
}
1832

1933
// Import server components
2034
import { createServer, startServer } from './server/server.js';

0 commit comments

Comments
 (0)