Overview
src/lib/logging/index.ts lines 19-28 attempt to dynamically require('async_hooks') inside an ES module. require() is not available in native ESM contexts (which Next.js 15 uses by default with type: module in package.json). This causes a ReferenceError: require is not defined at startup in certain environments, disabling the async-context-based request correlation.
Specifications
Features:
- Async context tracking uses ESM-compatible APIs
- Logger correctly associates log entries with the current request context
Tasks:
- Replace require('async_hooks') with a top-level import { AsyncLocalStorage } from 'node:async_hooks'
- Wrap the import in a dynamic await import('node:async_hooks') if conditional loading is needed
- Test that async context is correctly propagated through await chains
Impacted Files:
Acceptance Criteria
- No require() call exists in src/lib/logging/index.ts
- Logger starts without errors in the Next.js runtime
- Request IDs are correctly associated across async boundaries
Overview
src/lib/logging/index.ts lines 19-28 attempt to dynamically require('async_hooks') inside an ES module. require() is not available in native ESM contexts (which Next.js 15 uses by default with type: module in package.json). This causes a ReferenceError: require is not defined at startup in certain environments, disabling the async-context-based request correlation.
Specifications
Features:
Tasks:
Impacted Files:
Acceptance Criteria