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

vercel with astro framework throws bug #1777

Closed
wanghsinche opened this issue Apr 30, 2023 · 3 comments
Closed

vercel with astro framework throws bug #1777

wanghsinche opened this issue Apr 30, 2023 · 3 comments
Assignees
Labels

Comments

@wanghsinche
Copy link

Describe the bug

TypeError: Class extends value undefined is not a constructor or null
    at (entry.mjs:77:4827)
    at (render:middleware.js:1:17)

vercel API failed, but the static page works.
**It also works well in my local machine, weird. **
vercel node version is 18.x
the stripe package version is "stripe": "^12.3.0"

To Reproduce

page/api/stripe.ts

import type { APIRoute } from 'astro';
import Stripe from 'stripe';

const stripeKey: string = import.meta.env.STRIPE_APIKEY;
const webhookSecret: string = import.meta.env.STRIPE_WEBHOOK_SECRET;

export const post: APIRoute = async ({ request }) => {
  const signature = request.headers.get('Stripe-Signature');

  const stripe = new Stripe(stripeKey, {
    // This is needed to use the Fetch API rather than relying on the Node http
    // package.
    apiVersion: '2022-11-15',
  });

  return new Response(JSON.stringify({ msg: 'ok' }), { status: 200 });
};

Env:

vercel API failed, but the static page works. 
**It also works well in my local machine, weird. **
vercel node version is 18.x
the stripe package version is  "stripe": "^12.3.0"

Expected behavior

it should work in vercel

Code snippets

// pages/api/stripe.ts

import type { APIRoute } from 'astro';
import Stripe from 'stripe';

const stripeKey: string = import.meta.env.STRIPE_APIKEY;
const webhookSecret: string = import.meta.env.STRIPE_WEBHOOK_SECRET;

export const post: APIRoute = async ({ request }) => {
  const signature = request.headers.get('Stripe-Signature');

  const stripe = new Stripe(stripeKey, {
    // This is needed to use the Fetch API rather than relying on the Node http
    // package.
    apiVersion: '2022-11-15',
  });

  return new Response(JSON.stringify({ msg: 'ok' }), { status: 200 });
};

OS

linux

Node version

Node 18.x

Library version

12.3.0

API version

2022-11-15

Additional context

No response

@anniel-stripe
Copy link
Contributor

Hi @wanghsinche , this appears to be the same issue as #1732 that is caused by an internal class extending the Event Web API, which the Vercel edge runtime doesn't support yet. In the meantime, you can use a polyfill (event-target-polyfill) for the Event API as suggested in vercel/edge-runtime#293.

@anniel-stripe anniel-stripe self-assigned this Apr 30, 2023
@wanghsinche
Copy link
Author

wanghsinche commented May 1, 2023

Hi @wanghsinche , this appears to be the same issue as #1732 that is caused by an internal class extending the Event Web API, which the Vercel edge runtime doesn't support yet. In the meantime, you can use a polyfill (event-target-polyfill) for the Event API as suggested in vercel/edge-runtime#293.

It works! Thank you so much and so quick reply!!! it is not easy to locate the reason. I struggled with it for a whole night without any progress. 😂

@anniel-stripe
Copy link
Contributor

Glad it worked out! I'll close this issue as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants