Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use SDK in Vercel serverless environment due to proxy-agent dependency. #310

Closed
4 tasks done
andrusch opened this issue Aug 13, 2024 · 2 comments
Closed
4 tasks done
Assignees
Labels
bug Something isn't working

Comments

@andrusch
Copy link

Description of the Issue

I've built a NextJS app and have included the Box SDK within some API routes. These routes work locally and also from a clean GitPod environment. When the NextJS route is deployed to Vercel, I receive the following error when trying to execute any of the API routes that include Box SDK.

Steps to Reproduce

  1. Create a NextJS starter project and place the lines of code below in an API route folder. This example is for demonstratable purposes only. Get Started with NextJS
import {
  BOX_CLIENT_ID,
  BOX_CLIENT_SECRET,
  BOX_CONTRACT_TEMPLATE_ID,
  BOX_ENTERPRISE_ID,
  BOX_USER_ID,
} from '@/constants'
import { BoxCcgAuth } from 'box-typescript-sdk-gen'

export async function GET(
  req: NextRequest
) {
  try {
    const authClient = new BoxCcgAuth({ config: this._config });
    const tokenResponse = await authClient.withUserSubject(BOX_USER_ID as string).retrieveToken()
    return NextResponse.json({ success: true }, { status: 200 })
  } catch (e) { return NextResponse.json({ success: false }, { status: 400 }) }
}
  1. Deploy to Vercel.com with the free plan
  2. Call the API from Postman

Expected Behavior

You should receive a 200

Error Message, Including Stack Trace

⨯ Error: Cannot find module 'proxy-agent'
Require stack:
- /var/task/.next/server/chunks/295.js
- /var/task/.next/server/webpack-runtime.js
- /var/task/.next/server/instrumentation.js
- /var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js
- /var/task/___next_launcher.cjs
- /opt/rust/nodejs.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at /var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:11:25613
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at /opt/rust/nodejs.js:1:11604
    at Function.or (/opt/rust/nodejs.js:1:11978)
    at e.<computed>.te._load (/opt/rust/nodejs.js:1:11574)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at b.require (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:11:25829)
    at a (/opt/rust/bytecode.js:1:1075)
    at createAgent (/var/task/.next/server/chunks/295.js:1:37998) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/.next/server/chunks/295.js',
    '/var/task/.next/server/webpack-runtime.js',
    '/var/task/.next/server/instrumentation.js',
    '/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js',
    '/var/task/___next_launcher.cjs',
    '/opt/rust/nodejs.js'
  ]
}

Versions Used

Typescript SDK: "box-typescript-sdk-gen": "^1.1.0"
Platform: Vercel
Node.js (if applicable): 20x
"typescript": "^5.3.3"

@congminh1254
Copy link
Member

Hi @andrusch

Can you take a look at this comment

Please let me know if it works for your case.

Bests,
Minh

@andrusch
Copy link
Author

Hey @congminh1254

Yep, this resolved the issue. Apologies for not finding that ahead of opening this.

Best,
Charlie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants