1 ---
2 sidebar_label: "Vercel"
3 ---
4
5 import RewritesError from "../../../troubleshooting/_sections/storefront/rewrites.mdx"
6 import { Prerequisites, DetailsList } from "docs-ui"
7
8 export const metadata = {
9 title: `Deploy Next.js Starter Storefront to Vercel`,
10 }
11
12 # {metadata.title}
13
14 In this guide, you’ll learn how to deploy the Next.js Starter Storefront to [Vercel](https://vercel.com).
15
16 <Note title="Deploy with Cloud" type="success">
17
18 Cloud supports deploying [storefronts](!cloud!/storefront) alongside your Medusa application with zero-configuration.
19
20 Cloud is our managed services offering that makes deploying and operating Medusa applications possible without having to worry about configuring, scaling, and maintaining infrastructure. Cloud hosts your server, Admin dashboard, storefront, database, and Redis instance.
21
22 With Cloud, you maintain full customization control as you deploy your own modules and customizations directly from GitHub:
23
24 - Push to deploy.
25 - Multiple testing environments.
26 - Preview environments for new PRs.
27 - Test on production-like data.
28 - Storefront deployment.
29 - Emails setup.
30 - [And more](!cloud!#cloud-features).
31
32 [Sign up and learn more about Cloud](!cloud!/sign-up).
33
34 </Note>
35
36 <Prerequisites items={[
37 {
38 text: "Storefront codebase hosted in a GitHub repository.",
39 link: "../../../nextjs-starter/page.mdx"
40 },
41 {
42 text: "Deployed Medusa application with at least one region.",
43 link: "../../page.mdx#medusa-application"
44 },
45 ]} />
46
47 ## 1. Create Vercel Project
48
49 On your Vercel dashboard:
50
51 1. Click on the Add New button at the top right.
52 2. Choose Project from the dropdown.
53 3. In the list of repositories, click on the Import button of the storefront’s repository.
54
55 This opens a form to configure your project.
56
57 ### Configure Storefront Project
58
59 In the Configure Project form, choose Next.js for the Framework Preset field. This sets for you the build and install scripts, and the output directory
60
61 <Details summaryContent="Expected Values">
62
63 - `build` script:
64
65 ```bash npm2yarn
66 npm run build
67 ```
68
69 - `install` script:
70
71 ```bash npm2yarn
72 npm install
73 ```
74
75 - output directory: `.next`
76
77 </Details>
78
79 Then, expand the Environment Variables section and add the following variables:
80
81 ```bash
82 MEDUSA_BACKEND_URL= # URL of Medusa application
83 NEXT_PUBLIC_DEFAULT_REGION=us # or a different region that you prefer
84 NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY= # publishable API key of the storefront's sales channel
85 REVALIDATE_SECRET=supersecret # TODO generate random string
86 ```
87
88 Where:
89
90 1. `MEDUSA_BACKEND_URL` is the URL of your deployed Medusa application
91 2. `NEXT_PUBLIC_DEFAULT_REGION` is the country code of a region to be used by default, if the customer hasn’t selected a region.
92 3. `NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY` is the publishable API key of the storefront. You can create one or find the default one in the Medusa Admin dashboard.
93 4. `REVALIDATE_SECRET` is a random string for [Next.js revalidation](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#on-demand-revalidation).
94
95 Make sure to add other relevant environment variables. For example, if you’re using the Stripe Payment Module Provider in the Medusa application, add the `NEXT_PUBLIC_STRIPE_KEY` environment variable.
96
97 ### Deploy Application
98
99 Click the Deploy button when you’re done. The deployment will take a few minutes.
100
101 Once the deployment is done, there’s still more work to do before you can use the storefront. Click on the Continue to Dashboard button to go to the project’s dashboard.
102
103 ---
104
105 ## 2. Set Storefront URL
106
107 Vercel generates a random domain name for your project. You can use it or [set a custom domain name](https://vercel.com/guides/how-do-i-add-a-custom-domain-to-my-vercel-project).
108
109 <Note title="Tip">
110
111 Find your generated domain name at Settings → Domains in your project’s dashboard.
112
113 </Note>
114
115 Once you have your domain name:
116
117 1. Go to Settings → Environment Variables
118 2. Add a new environment variable:
119
120 ```bash
121 NEXT_PUBLIC_BASE_URL=https://nextjs-storefront...
122 ```
123
124 Set the value to the storefront’s URL.
125
126 ### Set STORE_CORS and AUTH_CORS in Deployed Medusa Application
127
128 You must also set the `STORE_CORS` environment variable in your Medusa application to the storefront’s URL:
129
130 ```bash
131 STORE_CORS=https://nextjs-storefront...
132 ```
133
134 <Note title="Tip">
135
136 If you have multiple storefront URLs, separate them by commas in `STORE_CORS`
137
138 </Note>
139
140 And add the URL to `AUTH_CORS`'s value:
141
142 ```bash
143 AUTH_CORS=<OTHER_URLS>,https://nextjs-storefront...
144 ```
145
146 Where `<OTHER_URLS>` are other storefront or admin URLs added previously to `AUTH_CORS`.
147
148 ### Redeploy Storefront
149
150 Once the environment variables changes are deployed in the Medusa application, do the following to redeploy the storefront:
151
152 1. Go to Deployments in the storefront Vercel project.
153 2. Find the last production deployment, and click on the three dots icon at the right.
154 3. Choose Redeploy from the dropdown, and confirm redeployment in the new window.
155
156 ---
157
158 ## Test the Deployed Storefront
159
160 Once the redeployment is done, test out the storefront by going to its URL. Try to browse the products or place an order to ensure everything is working as expected.
161
162 ---
163
164 ## Troubleshooting
165
166 If you’re running into issues in your storefront, find the logs in your Vercel project’s dashboard under the Logs tab.
167
168 <DetailsList
169 sections={[
170 {
171 title: "Login Page Error",
172 content: <RewritesError />
173 }
174 ]}
175 />