-
Notifications
You must be signed in to change notification settings - Fork 634
Closed
Labels
bugThis issue is a bug.This issue is a bug.needs-triageThis issue or PR still needs to be triaged.This issue or PR still needs to be triaged.
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
I'm encountering a runtime error in a Next.js (v13+) API route that handles Stripe webhooks. The error occurs during the build/deployment process in AWS Amplify, and I can't pinpoint the exact cause.
TypeError: Cannot destructure property 'environmentVariableSelector' of 'undefined' as it is undefined.
at d (.next/server/chunks/5936.js:15:31351)
at eg (.next/server/chunks/5936.js:9:5315)
at new ex (.next/server/chunks/5936.js:9:6739)
at 11151 (.next/server/app/api/stripe/webhook/route.js:1:4571)
Regression Issue
- Select this option if this issue appears to be a regression.
SDK version number
@aws-sdk/client-cognito-identity-provider": "^3.654.0"
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v21.1.0
Reproduction Steps
Stripe Webhook API Route: app/api/stripe/webhook/route.js
import { NextResponse } from "next/server";
import Stripe from "stripe";
import { updateUserGroupStripe } from "@/lib/actions/admin.action";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
export async function POST(req) {
try {
const text = await req.text();
const sig = req.headers.get("stripe-signature");
const event = stripe.webhooks.constructEvent(
text,
sig,
process.env.STRIPE_WEBHOOK_SECRET
);
await updateUserGroupStripe(payload);
return NextResponse.json({ received: true });
} catch (err) {
console.error(`❌ Error:`, err.message);
return NextResponse.json({ error: err.message }, { status: 400 });
}
}
updateUserGroupStripe function (uses Cognito SDK v3):
import {
CognitoIdentityProviderClient,
AdminUpdateUserAttributesCommand,
} from "@aws-sdk/client-cognito-identity-provider";
const client = new CognitoIdentityProviderClient({
region: process.env.COGNITO_REGION,
credentials: {
accessKeyId: process.env.COGNITO_ACCESS_KEY_ID,
secretAccessKey: process.env.COGNITO_ACCESS_SECRET,
},
});
export async function updateUserGroupStripe({ username, ... }) {
const command = new AdminUpdateUserAttributesCommand({
UserPoolId: process.env.COGNITO_USER_POOL_ID,
Username: username,
UserAttributes: attributesToUpdate,
});
await client.send(command);
}
All required environment variables are configured correctly in AWS Amplify and are accessible locally.
Observed Behavior
-Error only occurs in Amplify build
- locally works fine with the same .env configuration
- seems like something internal in the SDK is relying on environmentVariableSelector, but it is undefined
Expected Behavior
Handle missing internal config defaults gracefully
Possible Solution
No response
Additional Information/Context
No response
Metadata
Metadata
Assignees
Labels
bugThis issue is a bug.This issue is a bug.needs-triageThis issue or PR still needs to be triaged.This issue or PR still needs to be triaged.