diff --git a/eslint.config.mjs b/eslint.config.mjs index 151a3817..1573ebc1 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -24,6 +24,7 @@ export default tseslint.config( 'examples/realtime-demo/**', 'examples/nextjs/**', 'integration-tests//**', + 'tsc-multi.json', ]), eslint.configs.recommended, tseslint.configs.recommended, diff --git a/packages/agents-core/src/shims/shims-node.ts b/packages/agents-core/src/shims/shims-node.ts index ec0608bf..5f029835 100644 --- a/packages/agents-core/src/shims/shims-node.ts +++ b/packages/agents-core/src/shims/shims-node.ts @@ -14,11 +14,18 @@ declare global { // circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims' export function loadEnv(): Record { if (typeof process === 'undefined' || typeof process.env === 'undefined') { - if ( - typeof import.meta === 'object' && - typeof import.meta.env === 'object' - ) { - return import.meta.env as unknown as Record; + // In CommonJS builds, import.meta is not available, so we return empty object + try { + // Use eval to avoid TypeScript compilation errors in CommonJS builds + const importMeta = (0, eval)('import.meta'); + if ( + typeof importMeta === 'object' && + typeof importMeta.env === 'object' + ) { + return importMeta.env as unknown as Record; + } + } catch { + // import.meta not available (CommonJS build) } return {}; } diff --git a/packages/agents-core/src/shims/shims-workerd.ts b/packages/agents-core/src/shims/shims-workerd.ts index ffdb03e7..d5d888f9 100644 --- a/packages/agents-core/src/shims/shims-workerd.ts +++ b/packages/agents-core/src/shims/shims-workerd.ts @@ -15,11 +15,18 @@ declare global { // circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims' export function loadEnv(): Record { if (typeof process === 'undefined' || typeof process.env === 'undefined') { - if ( - typeof import.meta === 'object' && - typeof import.meta.env === 'object' - ) { - return import.meta.env as unknown as Record; + // In CommonJS builds, import.meta is not available, so we return empty object + try { + // Use eval to avoid TypeScript compilation errors in CommonJS builds + const importMeta = (0, eval)('import.meta'); + if ( + typeof importMeta === 'object' && + typeof importMeta.env === 'object' + ) { + return importMeta.env as unknown as Record; + } + } catch { + // import.meta not available (CommonJS build) } return {}; } diff --git a/tsc-multi.json b/tsc-multi.json index 104f0829..ddf444ca 100644 --- a/tsc-multi.json +++ b/tsc-multi.json @@ -1,6 +1,6 @@ { "targets": [ - { "extname": ".js", "module": "es2022", "moduleResolution": "node" }, + { "extname": ".js", "module": "commonjs", "moduleResolution": "node" }, { "extname": ".mjs", "module": "esnext" } ], "projects": [