vercel / nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.
https://subscription-payments.vercel.app/
MIT License
6.23k stars 1.27k forks source link

Failure to deploy with current instructions #151

Closed rdylina closed 1 year ago

rdylina commented 1 year ago

The current set of instructions when followed yield the following deployment errors:

[09:47:45.008] Cloning github.com/rdylina/rei-underwrite (Branch: main, Commit: 0210df7) [09:47:45.014] Skipping build cache since Vercel CLI used --force option [09:47:45.521] Cloning completed: 513.015ms [09:47:45.927] Running "vercel build" [09:47:46.435] Vercel CLI 28.10.0 [09:47:46.736] Installing dependencies... [09:47:47.100] yarn install v1.22.17 [09:47:47.142] [1/4] Resolving packages... [09:47:47.948] [2/4] Fetching packages... [09:47:56.387] [3/4] Linking dependencies... [09:47:58.633] [4/4] Building fresh packages... [09:47:58.873] success Saved lockfile. [09:47:58.879] Done in 11.78s. [09:47:58.907] Detected Next.js version: 12.3.0 [09:47:58.909] Running "yarn run build" [09:47:59.183] yarn run v1.22.17 [09:47:59.210] $ next build [09:47:59.649] Attention: Next.js now collects completely anonymous telemetry regarding usage. [09:47:59.649] This information is used to shape Next.js' roadmap and prioritize features. [09:47:59.650] You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL: [09:47:59.650] https://nextjs.org/telemetry [09:47:59.650] [09:47:59.776] info - Linting and checking validity of types... [09:48:03.431] info - Creating an optimized production build... [09:48:04.998] Browserslist: caniuse-lite is outdated. Please run: [09:48:04.998] npx browserslist@latest --update-db [09:48:04.998] Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating [09:48:12.598] info - Compiled successfully [09:48:12.599] info - Collecting page data... [09:48:15.061] info - Generating static pages (0/4) [09:48:15.113] info - Generating static pages (1/4) [09:48:15.119] (node:508) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time [09:48:15.120] (Use node --trace-warnings ... to show where the warning was created) [09:48:15.124] info - Generating static pages (2/4) [09:48:15.145] info - Generating static pages (3/4) [09:48:15.474] Could not find a relationship between 'products' and 'prices' in the schema cache [09:48:15.474] info - Generating static pages (4/4) [09:48:15.475] [09:48:15.475] Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error [09:48:15.475] [object Object] [09:48:15.475] [09:48:15.476] > Build error occurred [09:48:15.478] Error: Export encountered errors on following paths: [09:48:15.478] / [09:48:15.478] at /vercel/path0/node_modules/next/dist/export/index.js:394:19 [09:48:15.479] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [09:48:15.479] at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20) [09:48:15.479] at async /vercel/path0/node_modules/next/dist/build/index.js:1168:21 [09:48:15.479] at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20) [09:48:15.479] at async /vercel/path0/node_modules/next/dist/build/index.js:1044:17 [09:48:15.479] at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:79:20) [09:48:15.480] at async Object.build [as default] (/vercel/path0/node_modules/next/dist/build/index.js:65:29) [09:48:15.516] error Command failed with exit code 1. [09:48:15.518] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. [09:48:15.538] Error: Command "yarn run build" exited with 1

e2corporation commented 1 year ago

@rdylina There are several things off with this starter kit. The first problem to solve is the Supabase schema's not being setup correctly when the stripe fixtures are loaded, this will lead to a deployment failure.

[09:48:15.474] Could not find a relationship between 'products' and 'prices' in the schema cache

You will need to create the public schema in your Supabase project manually. For id fields, be sure to use text column type, and json type for all other object columns

  1. Create products table
  2. Create prices table (Ensure Foreign Key of product_id to id on products table)

As far as how to structure the columns, we can infer that from the model interfaces defined in types.ts

product table schema (Reference Model)

export interface Product {
  id: string /* primary key */;
  active?: boolean;
  name?: string;
  description?: string;
  image?: string;
  metadata?: Stripe.Metadata;
}
export interface Price {
  id: string /* primary key */;
  product_id?: string /* foreign key to products.id */;
  active?: boolean;
  description?: string;
  unit_amount?: number;
  currency?: string;
  type?: Stripe.Price.Type;
  interval?: Stripe.Price.Recurring.Interval;
  interval_count?: number;
  trial_period_days?: number | null;
  metadata?: Stripe.Metadata;
  products?: Product;
}

You will also want to ensure that the Next.js Framework Preset is selected on Build & Development Settings section.

Screen Shot 2023-01-01 at 5 24 48 AM
e2corporation commented 1 year ago

Postgres Table Definitions

CREATE TABLE "public"."products" (
    "id" text NOT NULL,
    "active" bool,
    "name" text,
    "description" text,
    "image" text,
    "metadata" json,
    PRIMARY KEY ("id")
);
CREATE TABLE "public"."prices" (
    "id" text NOT NULL,
    "product_id" text,
    "active" bool,
    "description" text,
    "unit_amount" numeric,
    "currency" text,
    "type" text,
    "interval" text,
    "interval_count" numeric,
    "trial_period_days" numeric,
    "metadata" json,
    "products" json,
    CONSTRAINT "prices_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "public"."products"("id"),
    PRIMARY KEY ("id")
);
e2corporation commented 1 year ago

Better yet, there is a shema.sql file in the Project root with all the needed tables. This needs to be loaded in the Supabase SQL Editor then RUN to create all the missing tables. Afterwards, start the stripe Webhooks listener and then load the stripe fixtures.

rdylina commented 1 year ago

@e2corporation Thank you for the detail responses, I glossed right over the fact it couldn't locate the table. As you said it turns out there is a scheme already. In fact it was already present in the SQL editor on supabase. I just had to run the query and naturally it finished deploying.

image

The setup instructions really ought to be updated to include these steps for someone who is new to this stack/environment.

Now I am just working towards getting webhooks working with stripe to populate the product data. So far no luck, gets zero response from the Vercel webhook endpoint.

e2corporation commented 1 year ago

@rdylina No problem, You may need to re-trigger a deployment after loading the price fixtures once. You also have to ensure the stripe listener is running locally before you load the fixtures. Once that is complete, going forward you modify products on your Stripe Dashboard Products section. (You'll need to have the Webhooks configured for all events for both local and production for price syncing to work). It takes the right timing and order of steps to get everything rendering correctly.

There are still some sync issues to be worked out with the products as well.

northrn commented 1 year ago

@rydlina Many of Vercel's templates don't work when deploying which is incredibly frustrating. If they don't want to update the repos with the proper code, then they should at least include the instructions to fix it on the users end. Lots of errors when using these starter templates that you think should be working.

rdylina commented 1 year ago

It is surprising that such a forward-thinking and rapidly growing company would have issues with the functionality of its starter templates. One would expect them to prioritize the maintenance and reliability of these templates to facilitate the adoption of their product. I hope they make the effort to update them all soon.

On Tue, Jan 3, 2023 at 7:59 PM northrn @.***> wrote:

@rydlina Many of Vercel's templates don't work when deploying which is incredibly frustrating. If they don't want to update the repos with the proper code, then they should at least include the instructions to fix it on the users end. Lots of errors when using these starter templates that you think should be working.

— Reply to this email directly, view it on GitHub https://github.com/vercel/nextjs-subscription-payments/issues/151#issuecomment-1370461201, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADV4BIJCD2AA3TJHMC2S7DWQTYSBANCNFSM6AAAAAATNWCU4Y . You are receiving this because you were mentioned.Message ID: @.***>

e2corporation commented 1 year ago

There are a bit of pain points specifically with this particular subscription starter, I have to tryout some of the others, I think a lot has to do with the changing revisions of the react and supporting libraries around it along with how the instructions are outlined. It would take some maintenance to keep all of the templates running healthy. In retrospect, once it starts working then it starts to produce value. The Stripe API integration I'm finding also has workflow inconsistencies in local development versus production (this is on stripe not so much the Vercel starter kit), with local env refusing to redirect to checkout routine, for example. Although with some of the frustrations from tinkering with the default installation it makes you want to just start from scratch in the first place. The upside is that it all can be fixed with enough time and troubleshooting.

northrn commented 1 year ago

If you have found fixes to some of these problems it would be great if you could post them. I have it working locally without issue and the Stripe webhooks are functioning. I’m worried that I’m going to sink time into this only to find it doesn’t deploy… 

stevenmdc commented 1 year ago

If anyone have the steps for run this project in 2023, i ( and community )'ll be grateful...

e2corporation commented 1 year ago

@northrn What exact problems are you having? If you can post the exact issue I can help troubleshoot. My issues were mainly due to the fact that I cloned the repository myself manually then attached it as a Vercel Project, which did not automatically load the SQL Schema. So I was trying to run & build the project without the full schema intact initially until I got things sorted.

It's also ideal to configure local and production environments properly, which involves reading the Supbase docs for local environment setup (https://supabase.com/docs/guides/resources/supabase-cli/local-development).

Stripe configurations also need to be setup for Local and Prod Environments (Product/Pricing setup).

Before deploying to Vercel, the project should be able to complete the build process locally. Chances are if you can build locally, it will most likely complete a a deployment.

e2corporation commented 1 year ago

@Baggi4 The existing readme covers the essentials of what's needed, although the instructions need to be followed in the correct order otherwise products/data won't be loaded or synchronized etc.

What exact problems are you having with setup?

leerob commented 1 year ago

We're looking into this with the Supabase team!

cc @thorwebdev

thorwebdev commented 1 year ago

Hey everyone, sorry about this. It looks like this happens when the deployment is running before the Supabase Instance has been fully provisioned. We've updated the tarter to allow deployment even if the instance is still being set up. Sorry for this experience, and thank you for taking the time to report it and help improve it for others! 💚