Dev.to
5/13/2026

Fifteen lines of Proxy to keep an SDK from breaking my CI
Short summary
Next.js module compilation can break CI builds when SDKs validate credentials in their constructors, causing missing-secret errors during build time. A 15-line JavaScript Proxy pattern delays client instantiation until first use, solving this for rarely-exercised routes like webhooks. The pattern is reusable across SDKs (Stripe, Twilio, OpenAI, Anthropic) but less effective if the SDK is used everywhere in the app.
- •Next.js compiles all imported modules at build time, triggering SDK validation errors even if routes never execute
- •JavaScript Proxy pattern delays SDK client creation until first property access, eliminating build-time failures
- •Pattern is copyable across SDKs and requires only 15 lines of code with minimal changes to existing call sites
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



