const { getDefaultConfig } = require('expo/metro-config');

const config = getDefaultConfig(__dirname);

// Redirect openai .mjs ESM imports to .js CJS to avoid TDZ circular dependency errors on web
config.resolver.resolveRequest = (context, moduleName, platform) => {
  if (
    context.originModulePath.includes('node_modules/openai') &&
    moduleName.endsWith('.mjs')
  ) {
    return context.resolveRequest(context, moduleName.replace(/\.mjs$/, '.js'), platform);
  }
  return context.resolveRequest(context, moduleName, platform);
};

module.exports = config;
