1 import { Table, DetailsList, Prerequisites } from "docs-ui"
2 import PortForwardingTroubleshooting from "../troubleshooting/_sections/create-medusa-app-errors/forwarding.mdx"
3 import DBUrlTroubleshooting from "../troubleshooting/_sections/create-medusa-app-errors/db-url-error.mdx"
4 import EaddrinuseTroubleshooting from "../troubleshooting/_sections/other/eaddrinuse.mdx"
5 import DockerTroubleshooting from "../troubleshooting/_sections/database-errors/docker.mdx"
6 import EagainTroubleshooting from "../troubleshooting/_sections/create-medusa-app-errors/eagain-error.mdx"
7 import TypeErrorTroubleshooting from "../troubleshooting/_sections/create-medusa-app-errors/typeerror.mdx"
8 import ConnectionErrorTroubleshooting from "../troubleshooting/_sections/database-errors/connection-error.mdx"
9 import NoBrowserTroubleshooting from "../troubleshooting/_sections/create-medusa-app-errors/no-browser-token-error.mdx"
10 import OtherErrorsTroubleshooting from "../troubleshooting/_sections/create-medusa-app-errors/other-errors.mdx"
11
12 export const metadata = {
13 title: `create-medusa-app CLI Tool`,
14 }
15
16 # {metadata.title}
17
18 The `create-medusa-app` CLI tool simplifies the process of creating a new Medusa project. It creates a monorepo containing your Medusa backend application and, optionally, a storefront. It also allows you to setup a [Medusa plugin project](#create-a-medusa-plugin-project).
19
20 <Prerequisites items={[
21 {
22 text: "Node.js v20.19.0+ or v22.12.0+",
23 link: "https://nodejs.org/en/download"
24 },
25 {
26 text: "Git CLI tool",
27 link: "https://git-scm.com/downloads"
28 },
29 {
30 text: "PostgreSQL",
31 link: "https://www.postgresql.org/download/"
32 }
33 ]} />
34
35 ## Usage
36
37 ```bash npx2yarnExec
38 npx create-medusa-app@latest [project-name]
39 ```
40
41 The command will use the package manager you run it with to create a new Medusa project in a directory named after the provided `project-name`.
42
43 ### Arguments
44
45 <Table>
46 <Table.Header>
47 <Table.Row>
48 <Table.HeaderCell>
49 Option
50 </Table.HeaderCell>
51 <Table.HeaderCell>
52 Description
53 </Table.HeaderCell>
54 </Table.Row>
55 </Table.Header>
56 <Table.Body>
57 <Table.Row>
58 <Table.Cell>
59
60 `project-name`
61
62 </Table.Cell>
63 <Table.Cell>
64 The name of the project's directory and PostgreSQL database to be created. For example, `my-medusa-store`. If not provided, you'll be prompted to enter a project name.
65 </Table.Cell>
66 </Table.Row>
67 </Table.Body>
68 </Table>
69
70 ### Command Options
71
72 <Table>
73 <Table.Header>
74 <Table.Row>
75 <Table.HeaderCell>
76 Option
77 </Table.HeaderCell>
78 <Table.HeaderCell>
79 Description
80 </Table.HeaderCell>
81 <Table.HeaderCell>
82 Default
83 </Table.HeaderCell>
84 </Table.Row>
85 </Table.Header>
86 <Table.Body>
87 <Table.Row>
88 <Table.Cell>
89
90 `--repo-url <url>`
91
92 </Table.Cell>
93 <Table.Cell>
94 The repository URL to create the project from.
95 </Table.Cell>
96 <Table.Cell>
97
98 `https://github.com/medusajs/dtc-starter`
99
100 </Table.Cell>
101 </Table.Row>
102 <Table.Row>
103 <Table.Cell>
104
105 `--no-browser`
106
107 </Table.Cell>
108 <Table.Cell>
109
110 Disables opening the browser at the end of the project creation and only shows success message.
111
112 </Table.Cell>
113 <Table.Cell>
114
115 `false`
116
117 </Table.Cell>
118 </Table.Row>
119 <Table.Row>
120 <Table.Cell>
121
122 `--skip-db`
123
124 </Table.Cell>
125 <Table.Cell>
126
127 Skips creating the database, running migrations, and seeding, and subsequently skips opening the browser. Useful if you want to set the database URL with the `--db-url` option.
128
129 </Table.Cell>
130 <Table.Cell>
131
132 `false`
133
134 </Table.Cell>
135 </Table.Row>
136 <Table.Row>
137 <Table.Cell>
138
139 `--db-url <url>`
140
141 </Table.Cell>
142 <Table.Cell>
143
144 Skips database creation and sets the database URL to the provided URL. Throws an error if connection to the database fails. Will still run migrations and open the admin after project creation. Useful if you already have a database created, locally or remotely.
145
146 </Table.Cell>
147 <Table.Cell>
148
149 \-
150
151 </Table.Cell>
152 </Table.Row>
153 <Table.Row>
154 <Table.Cell>
155
156 `--no-migrations`
157
158 </Table.Cell>
159 <Table.Cell>
160
161 Skips running migrations, creating admin user, and seeding. If used, it's expected that you pass the `--db-url` option with a URL of a database that has all necessary migrations. Otherwise, unexpected errors will occur. Helpful only if combined with `--db-url`.
162
163 </Table.Cell>
164 <Table.Cell>
165
166 `false`
167
168 </Table.Cell>
169 </Table.Row>
170 <Table.Row>
171 <Table.Cell>
172
173 `--directory-path <path>`
174
175 </Table.Cell>
176 <Table.Cell>
177
178 Allows specifying the parent directory path to create the directory of the new project in.
179
180 </Table.Cell>
181 <Table.Cell>
182
183 The current directory the command is running in.
184
185 </Table.Cell>
186 </Table.Row>
187 <Table.Row>
188 <Table.Cell>
189
190 `--with-nextjs-starter`
191
192 </Table.Cell>
193 <Table.Cell>
194
195 Installs the storefront in the `apps/storefront` directory within your project monorepo. If this option is not specified, the storefront directory is removed from the project.
196
197 </Table.Cell>
198 <Table.Cell>
199
200 `false`
201
202 </Table.Cell>
203 </Table.Row>
204 <Table.Row>
205 <Table.Cell>
206
207 `--verbose`
208
209 </Table.Cell>
210 <Table.Cell>
211
212 Shows detailed logs. Useful when you're reporting an issue with the tool.
213
214 </Table.Cell>
215 <Table.Cell>
216
217 `false`
218
219 </Table.Cell>
220 </Table.Row>
221 <Table.Row>
222 <Table.Cell>
223
224 `--plugin`
225
226 </Table.Cell>
227 <Table.Cell>
228
229 Create a [plugin project](#create-a-medusa-plugin-project) instead of a Medusa application. This option is available starting from [Medusa v2.3.0](https://github.com/medusajs/medusa/releases/tag/v2.3.0).
230
231 </Table.Cell>
232 <Table.Cell>
233
234 `false`
235
236 </Table.Cell>
237 </Table.Row>
238 <Table.Row>
239 <Table.Cell>
240
241 `--version`
242
243 </Table.Cell>
244 <Table.Cell>
245
246 Specify the Medusa version to install in the project. The specified version will be used for every `@medusajs/*` package in the Medusa and storefront projects.
247
248 </Table.Cell>
249 <Table.Cell>
250
251 The latest version of Medusa at the time of running the command.
252
253 </Table.Cell>
254 </Table.Row>
255 <Table.Row>
256 <Table.Cell>
257
258 `--use-npm`
259
260 </Table.Cell>
261 <Table.Cell>
262
263 Uses `npm` as the package manager to create the project, regardless of the package manager used to run the command.
264
265 </Table.Cell>
266 <Table.Cell>
267
268 The package manager used to run the command.
269
270 </Table.Cell>
271 </Table.Row>
272 <Table.Row>
273 <Table.Cell>
274
275 `--use-yarn`
276
277 </Table.Cell>
278 <Table.Cell>
279
280 Uses `yarn` as the package manager to create the project, regardless of the package manager used to run the command.
281
282 </Table.Cell>
283 <Table.Cell>
284
285 The package manager used to run the command.
286
287 </Table.Cell>
288 </Table.Row>
289 <Table.Row>
290 <Table.Cell>
291
292 `--use-pnpm`
293
294 </Table.Cell>
295 <Table.Cell>
296
297 Uses `pnpm` as the package manager to create the project, regardless of the package manager used to run the command.
298
299 </Table.Cell>
300 <Table.Cell>
301
302 The package manager used to run the command.
303
304 </Table.Cell>
305 </Table.Row>
306 </Table.Body>
307 </Table>
308
309 ## Examples
310
311 ### Connect to a Vercel PostgreSQL Database
312
313 To use a PostgreSQL database hosted on Vercel, use the `--db-url` option and add to the end of your connection URL `?sslmode=require`. For example:
314
315 ```bash npx2yarnExec
316 npx create-medusa-app@latest --db-url "postgres://default:<password><host-region>.postgres.vercel-storage.com:5432/verceldb?sslmode=require"
317 ```
318
319 <Note>
320
321 If the database already has the necessary migrations and you don't need the command to run migrations, you can pass the `--no-migrations` option.
322
323 </Note>
324
325 ### Connect to a Supabase Database
326
327 To connect to a Supabase database, use the `--db-url` option with its value being the connection URL to your Supabase database. For example:
328
329 ```bash npx2yarnExec
330 npx create-medusa-app@latest --db-url "postgres://postgres.<host>:<password>@aws-0-eu-central-1.pooler.supabase.com:5432/postgres"
331 ```
332
333 <Note>
334
335 If the database already has the necessary migrations and you don't need the command to run migrations, you can pass the `--no-migrations` option.
336
337 </Note>
338
339 ---
340
341 ## Project Structure
342
343 The `create-medusa-app` tool creates a monorepo project with the following structure:
344
345 ```
346 my-medusa-store/
347 ├── apps/
348 │ ├── backend/ # Your Medusa backend application
349 │ │ ├── src/
350 │ │ ├── package.json
351 │ │ └── medusa-config.ts
352 │ └── storefront/ # Storefront (if --with-nextjs-starter is used)
353 │ ├── src/
354 │ ├── package.json
355 │ └── next.config.js
356 ├── package.json # Root package.json for workspace management
357 └── pnpm-workspace.yaml # Workspace configuration
358 ```
359
360 Your Medusa backend will be located in the `apps/backend` directory, and the optional storefront in `apps/storefront`.
361
362 ---
363
364 ## Create a Medusa Plugin Project
365
366 The `create-medusa-app` tool can also be used to create a Medusa Plugin Project. You can do that by passing the `--plugin` option:
367
368 ```bash npx2yarnExec
369 npx create-medusa-app@latest my-plugin --plugin
370 ```
371
372 Learn more about how to create a plugin in [this documentation](!docs!/learn/fundamentals/plugins).
373
374 ---
375
376 ## Install a Specific Medusa Version
377
378 To install a specific version of Medusa, use the `--version` option. This will install the specified version for every `@medusajs/*` package in the Medusa and storefront projects. For example:
379
380 ```bash npx2yarnExec
381 npx create-medusa-app@latest my-medusa-store --version 2.3.0
382 ```
383
384 This will create a new Medusa project with the `2.3.0` version.
385
386 ---
387
388 ## Troubleshooting
389
390 <DetailsList
391 sections={[
392 {
393 title: "Errors when using VSCode or GitHub Codespaces",
394 content: <PortForwardingTroubleshooting />
395 },
396 {
397 title: "Can't connect to database with --db-url option",
398 content: <DBUrlTroubleshooting />
399 },
400 {
401 title: "Error: EADDRINUSE",
402 content: <EaddrinuseTroubleshooting />
403 },
404 {
405 title: "Can't Connect to PostgreSQL Docker Container",
406 content: <DockerTroubleshooting />
407 },
408 {
409 title: "EAGAIN Error",
410 content: <EagainTroubleshooting />
411 },
412 {
413 title: "TypeError: cmd is not a function",
414 content: <TypeErrorTroubleshooting />
415 },
416 {
417 title: "Error: connect ECONNREFUSED ::1:5432",
418 content: <ConnectionErrorTroubleshooting />
419 },
420 {
421 title: "Invalid Token Error After Using --no-browser option",
422 content: <NoBrowserTroubleshooting />
423 },
424 {
425 title: "Other Errors",
426 content: <OtherErrorsTroubleshooting />
427 }
428 ]}
429 />