1 import { Note, InlineIcon } from "docs-ui"
2 import { EllipsisHorizontal } from "@medusajs/icons"
3
4 export const metadata = {
5 title: `Troubleshooting Cloud Deployments`,
6 }
7
8 # {metadata.title}
9
10 In this guide, you'll find solutions to common issues that may arise when deploying your Medusa applications on Cloud.
11
12 <Note>
13
14 If none of the issues in this guide match yours, [check the Cloud status page](../../status/page.mdx) for ongoing Cloud incidents. The bottom of the documentation's right sidebar also shows the current Cloud status.
15
16 </Note>
17
18 ## Troubleshooting Build and Deployment Issues with AI
19
20 When your build or deployment fails on Cloud, you can use the "Fix with AI" feature to troubleshoot and resolve the issue with the help of the [Cloud Assistant](../../assistant/page.mdx). The AI agent will analyze the deployment and build logs, identify the root cause of the issue, and provide you with actionable steps to resolve it.
21
22 Learn more in the [Fix Deployment and Build Issues with AI](../fix-with-ai/page.mdx) guide.
23
24 ---
25
26 ## Access Logs
27
28 When a deployment fails, you can see the [build](../../logs/page.mdx#view-build-logs-on-cloud) and [runtime logs](../../logs/page.mdx#view-runtime-logs-on-cloud) of your deployment to understand the cause of the failure.
29
30 Alternatively, you can install the [Cloud CLI](../../cli/page.mdx) and use it to check logs from your terminal or with the help of AI agents like Claude Code.
31
32 For example:
33
34 ```bash
35 # Install the CLI
36 npm install @medusajs/mcloud -g
37
38 # Login
39 mcloud login
40
41 # Check logs of the latest deployment in the environment
42 mcloud logs --organization org_123 --project proj_123 --environment env_123
43
44 # Check logs of a specific deployment
45 mcloud logs --organization org_123 --project proj_123 --environment env_123 --deployment-id deploy_123
46 ```
47
48 See the [Cloud CLI](../../cli/page.mdx) guide for more details on how to use the CLI to manage your Cloud resources and deployments.
49
50 ---
51
52 ## Files Not Found After Deployment
53
54 Before deploying your Medusa application on Cloud, Medusa runs the `build` script defined in your `package.json` file, then copies only the output of the [build process](!docs!/learn/build), which is the `.medusa/server` directory.
55
56 The `.medusa/server` directory holds the compiled JavaScript files of your project, the production build of the admin dashboard, and other necessary files to run your Medusa application in production.
57
58 If you have custom files needed at runtime, such as a `src/data` directory that holds JSON files, modify the `build` script in your `package.json` file to copy these files to the `.medusa/server` directory after the build process.
59
60 For example:
61
62 ```json title="package.json"
63 {
64 "scripts": {
65 "postbuild": "cp -r src/data .medusa/server/src/data",
66 "build": "medusa build && npm run postbuild"
67 }
68 }
69 ```
70
71 This script copies the `src/data` directory to the `.medusa/server` directory following the build process.
72
73 Learn more in the [Deployments Guide](../page.mdx#build-process-for-deployments).
74
75 <Note>
76
77 You can replace `npm run postbuild` with the appropriate command for your package manager, such as `yarn postbuild`.
78
79 </Note>
80
81 ---
82
83 ## Missing medusa-config.js in Build Output
84
85 If your deployment fails with an error similar to:
86
87 ```bash
88 Invalid build output: missing /build/apps/backend/.medusa/server/medusa-config.js.
89 Ensure tsconfig compilerOptions.outDir is .medusa/server (or unset), your package.json
90 build script runs medusa build, and the Medusa build step completed successfully.
91 ```
92
93 Cloud validates that the Medusa build output contains a compiled `medusa-config.js` file at `.medusa/server/medusa-config.js`. This file is produced when `medusa build` compiles your `medusa-config.ts` file to the `.medusa/server` directory.
94
95 The error occurs when one of the following is true:
96
97 - The `build` script in `package.json` does not run `medusa build`.
98 - The `tsconfig.json` file sets `compilerOptions.outDir` to a path other than `.medusa/server`, causing the build output to land in the wrong directory.
99 - The `medusa build` step failed silently or was skipped during the build.
100
101 ### Verify the build script
102
103 Open your `package.json` and confirm the `build` script calls `medusa build`:
104
105 ```json title="package.json"
106 {
107 "scripts": {
108 "build": "medusa build"
109 }
110 }
111 ```
112
113 If you have a custom post-build step, chain it after `medusa build`:
114
115 ```json title="package.json"
116 {
117 "scripts": {
118 "build": "medusa build && npm run postbuild"
119 }
120 }
121 ```
122
123 ### Check tsconfig.json outDir
124
125 Open `tsconfig.json` and check the `compilerOptions.outDir` value. Either remove it to use the default (`.medusa/server`), or set it explicitly to `.medusa/server`:
126
127 ```json title="tsconfig.json"
128 {
129 "compilerOptions": {
130 "outDir": ".medusa/server"
131 }
132 }
133 ```
134
135 <Note type="warning">
136
137 Setting `outDir` to any path other than `.medusa/server` causes the build output to land in the wrong location and triggers this error.
138
139 </Note>
140
141 ### Check the build logs
142
143 After verifying the script and `tsconfig.json`, check the build logs to confirm `medusa build` ran and completed without errors. If you see TypeScript compilation errors in the logs, fix them locally by running:
144
145 ```bash npm2yarn
146 npm run build
147 ```
148
149 Then commit the fixes and push to trigger a new deployment.
150
151 ---
152
153 ## Out of Memory (OOM) Build Failures
154
155 Exit code 137 indicates that your build process was killed by the system due to memory exhaustion. This commonly occurs with TypeScript-heavy monorepos during compilation.
156
157 ### Diagnosing Exit Code 137
158
159 Check your build logs for these indicators:
160
161 - **Exit code 137** at the end of the build process
162 - **"Killed"** message during TypeScript compilation
163 - Build terminating unexpectedly without clear error messages
164
165 ### Resolve OOM Build Failures
166
167 OOM Build failures typically occur when the TypeScript compiler faces complex types in your project. This commonly happens when there's mismatch between dependencies in your project.
168
169 For example, Medusa supports Zod v4.2.0. If you install a different version of Zod in your project, it can lead to complex type issues during compilation, causing OOM failures.
170
171 To resolve this, ensure that your project's dependencies are compatible with those used by Medusa or other dependencies.
172
173 ---
174
175 ## Missing yarn.lock in Build Context
176
177 If your Yarn berry monorepo build fails with the following error, the `yarn.lock` file is not included in the build context:
178
179 ```bash
180 failed to calculate checksum of ref: "/yarn.lock": not found
181 ```
182
183 This is different from an outdated lockfile. The lockfile is entirely absent from the build context. Cloud cannot install dependencies without it.
184
185 The most common cause is that `yarn.lock` is listed in `.gitignore` or was never committed to the repository.
186
187 ### Fix a Missing yarn.lock
188
189 1. Run `yarn install` locally to generate the lockfile:
190
191 ```bash
192 yarn install
193 ```
194
195 2. Commit the `yarn.lock` file to your repository:
196
197 ```bash
198 git add yarn.lock
199 git commit -m "Add yarn.lock"
200 git push
201 ```
202
203 3. Push the changes to trigger a new deployment.
204
205 ### Prevent Missing Lockfile Issues
206
207 Always commit your lockfile to version control. Cloud requires the lockfile to install dependencies with a frozen install, ensuring reproducible builds. Remove any line in your `.gitignore` that matches `yarn.lock` or `*.lock`.
208
209 ---
210
211 ## Outdated pnpm Lockfile
212
213 If your build fails with the following error, your `pnpm-lock.yaml` file is out of sync with `package.json`:
214
215 ```bash
216 ERR_PNPM_OUTDATED_LOCKFILE Cannot install with 'frozen-lockfile' because
217 pnpm-lock.yaml is not up to date with package.json
218 ```
219
220 Cloud uses `--frozen-lockfile` when installing dependencies to ensure reproducible builds. This means the lockfile must be committed and kept up to date with `package.json`.
221
222 To fix this error:
223
224 1. Run `pnpm install` locally to update the lockfile.
225 2. Commit the updated `pnpm-lock.yaml` file.
226 3. Push the changes to trigger a new deployment.
227
228 ---
229
230 ## Yarn Berry Frozen Lockfile Errors (YN0028/YN0086)
231
232 If your build fails with the following error, your `yarn.lock` file is out of sync with `package.json`:
233
234 ```bash
235 YN0028: The lockfile would have been modified by this install,
236 which is explicitly forbidden.
237 ```
238
239 or
240
241 ```bash
242 YN0086: Some peer dependencies are incorrectly met by your project;
243 run yarn explain peer-requirements <hash> for details, where <hash>
244 is the six-letter p-prefixed code.
245 ```
246
247 Medusa uses `--frozen-lockfile` (also known as immutable installs) during Cloud builds to ensure reproducible deployments. This means the `yarn.lock` file must be committed and kept in sync with your `package.json`. The error occurs when you add or update a dependency in `package.json` without running `yarn install` locally and committing the updated lockfile.
248
249 To fix this error:
250
251 1. Run `yarn install` locally to update the lockfile:
252
253 ```bash
254 yarn install
255 ```
256
257 2. Commit the updated `yarn.lock` file:
258
259 ```bash
260 git add yarn.lock
261 git commit -m "Update yarn.lock"
262 git push
263 ```
264
265 3. Push the changes to trigger a new deployment.
266
267 ---
268
269 ## Storefront Build Failed with Empty Logs
270
271 If your storefront build fails with a `build-failed` status but the build logs are empty or show minimal output, the cause is usually one of the following:
272
273 - An outdated lockfile that is out of sync with `package.json`
274 - Incompatible or missing dependencies in the monorepo
275
276 ### Check for Storefront Root Directory Misconfiguration
277
278 If the storefront build fails immediately (within 1-2 seconds) with no build logs and you see file retrieval errors, the storefront root directory configured in your Cloud project may not match the actual location of your storefront in the repository.
279
280 To verify and fix the storefront root directory:
281
282 1. If you're in a different organization, [switch to the organization](../../organizations/page.mdx#switch-organization).
283 2. Click **Projects** in the sidebar and select the project.
284 3. Click **Settings** in the sidebar.
285 4. Check the **Storefront root directory** field and confirm it matches the actual path of your storefront in the repository. For example, if your storefront is at `apps/storefront`, the field should contain `apps/storefront`.
286 5. If the path is incorrect, update it and save.
287 6. Trigger a new deployment.
288
289 Refer to the [Projects](../../projects/page.mdx) guide for details on editing the storefront root directory setting.
290
291 ---
292
293 ### Check for Lockfile Mismatches
294
295 Cloud installs dependencies with a frozen lockfile to ensure reproducible builds. If your lockfile is out of sync with `package.json`, the dependency installation step may fail silently.
296
297 To check and fix a lockfile mismatch:
298
299 1. Run your package manager's install command locally to regenerate the lockfile:
300
301 ```bash npm2yarn
302 npm install
303 ```
304
305 2. Commit the updated lockfile.
306 3. Push the changes to trigger a new deployment.
307
308 ### Retrieve Detailed Build Logs with the CLI
309
310 When the Cloud dashboard shows minimal or empty build logs, use the Cloud CLI to retrieve the full output:
311
312 ```bash
313 # Install the CLI
314 npm install @medusajs/mcloud -g
315
316 # Login
317 mcloud login
318
319 # List recent deployments to find the failed deployment's ID
320 mcloud deployments list \
321 --organization org_123 \
322 --project proj_123
323
324 # Fetch the storefront build logs for a specific deployment
325 mcloud deployments build-logs deploy_123 \
326 --organization org_123 \
327 --project proj_123 \
328 --type storefront
329 ```
330
331 Replace `org_123`, `proj_123`, and `deploy_123` with your actual IDs. You can find the deployment ID in the output of `mcloud deployments list` or in the Cloud dashboard's deployment details page.
332
333 ### Contact Support
334
335 If neither of the steps above resolves the issue and the storefront build logs remain empty, contact support and include the deployment ID so the team can investigate at the platform level.
336
337 ---
338
339 ## npm Peer Dependency Conflicts with Third-Party Packages
340
341 When you install a third-party package (for example, a payment provider) that requires a specific version of a Medusa package, npm may throw an `ERESOLVE` error if the required version doesn't match the version installed in your project.
342
343 For example, you may see an error similar to:
344
345 ```bash
346 npm error code ERESOLVE
347 npm error ERESOLVE unable to resolve dependency tree
348 npm error
349 npm error While resolving: my-medusa-app@1.0.0
350 npm error Found: @medusajs/framework@2.15.5
351 npm error node_modules/@medusajs/framework
352 npm error @medusajs/framework@"2.15.5" from the root project
353 npm error
354 npm error Could not resolve dependency:
355 npm error peer @medusajs/framework@"2.13.6" from @example/medusa-payment-example@0.1.0
356 ```
357
358 ### Recommended Resolution Strategies
359
360 Try the following strategies in order:
361
362 1. **Update the third-party package**: Check if a newer version of the package supports your Medusa version. Run:
363
364 ```bash npm2yarn
365 npm install @example/medusa-payment-example@latest
366 ```
367
368 2. **Contact the package maintainer**: If no compatible version exists, open an issue or contact the maintainer to request support for your Medusa version.
369
370 3. **Use `--legacy-peer-deps`**: If the version mismatch is minor (for example, a patch version difference) and you have confirmed the package works correctly, you can bypass the conflict. Add the following to a `.npmrc` file at the root of your project:
371
372 ```bash title=".npmrc"
373 legacy-peer-deps=true
374 ```
375
376 This tells npm to ignore peer dependency conflicts and install anyway. Use this as a last resort, and test your integration thoroughly before deploying.
377
378 <Note type="warning">
379
380 Using `--legacy-peer-deps` may introduce compatibility issues. Always test your application thoroughly after applying this workaround.
381
382 </Note>
383
384 ---
385
386 ## pnpm Lockfile Config Mismatch (ERR_PNPM_LOCKFILE_CONFIG_MISMATCH)
387
388 If your build fails with the following error, the `patchedDependencies` configuration in your `package.json` does not match what is recorded in `pnpm-lock.yaml`:
389
390 ```bash
391 ERR_PNPM_LOCKFILE_CONFIG_MISMATCH Cannot proceed with the frozen installation.
392 The current "patchedDependencies" configuration doesn't match
393 the value found in the lockfile
394 ```
395
396 This happens when you add, remove, or modify patch files in the `patches/` directory without regenerating the lockfile. Cloud uses `--frozen-lockfile` for reproducible builds, so the lockfile must reflect the current patch configuration.
397
398 To fix this error:
399
400 1. Run `pnpm install` locally to regenerate the lockfile.
401 2. Commit the updated `pnpm-lock.yaml` file.
402
403 ---
404
405 ## Private npm Registry Authentication Failures
406
407 If your storefront or backend build fails with an authentication error like the following, your private npm registry credentials are not available during the build:
408
409 ```bash
410 ERR_PNPM_FETCH_401 GET https://registry.example.com/my-package:
411 Response was 401 Unauthorized
412 ```
413
414 This occurs when packages are hosted on a private registry (for example, a company Artifactory instance or a scoped registry) and the build environment does not have the credentials to fetch them.
415
416 ### Configure Registry Credentials as Environment Variables
417
418 To provide registry credentials to Cloud builds:
419
420 1. [Add your registry auth token as an environment variable](../../environments/environment-variables/page.mdx#add-environment-variables-on-cloud) in your Cloud project. For example, add a variable named `NPM_TOKEN` with your token value.
421 2. In your project's `.npmrc` file, reference the environment variable:
422
423 ```bash title=".npmrc"
424 //registry.example.com/:_authToken=${NPM_TOKEN}
425 ```
426
427 3. Commit the updated `.npmrc` file to your repository.
428 4. Push the changes to trigger a new deployment.
429
430 <Note>
431
432 The `.npmrc` file must be committed to your repository for Cloud to use it during builds. The environment variable is injected at build time.
433
434 </Note>
435
436 ### Secondary Failures from Failed Dependency Installation
437
438 If the private registry authentication fails, `pnpm install` may fail silently or produce cryptic secondary errors such as missing binaries or missing modules. If you see unexpected errors after a build, check the build logs for `401 Unauthorized` or `ERR_PNPM_FETCH_401` errors earlier in the output.
439
440 ---
441
442 ## pnpm Install Frozen Lockfile Failures
443
444 If your Cloud build fails with exit code 1 during the `pnpm install` step and the error message only says "process did not complete successfully", the cause is often a lockfile or dependency issue that is hidden in pnpm's full output.
445
446 Cloud uses `--frozen-lockfile` when installing dependencies to ensure reproducible builds. This means your `pnpm-lock.yaml` must be committed and kept in sync with `package.json`.
447
448 ### Common Causes
449
450 - **Lockfile drift**: The `pnpm-lock.yaml` file was not committed after updating `package.json`.
451 - **pnpm version mismatch**: The version of pnpm used locally differs from the one used in Cloud builds.
452 - **Native build dependencies**: A package with native binaries fails to build in the Cloud environment.
453 - **Registry connectivity issues**: A package registry is unreachable during the build.
454
455 ### Retrieve Full Build Logs
456
457 The Cloud dashboard may truncate build output. Use the [Cloud CLI](../../cli/page.mdx) to retrieve the full pnpm install logs:
458
459 ```bash
460 # Install the CLI
461 npm install @medusajs/mcloud -g
462
463 # Login
464 mcloud login
465
466 # List recent deployments to find the failed deployment ID
467 mcloud deployments list \
468 --organization org_123 \
469 --project proj_123
470
471 # Fetch the full build logs
472 mcloud deployments build-logs deploy_123 \
473 --organization org_123 \
474 --project proj_123
475 ```
476
477 Replace `org_123`, `proj_123`, and `deploy_123` with your actual IDs.
478
479 ### Fix a Lockfile Mismatch
480
481 If the logs show a lockfile error, regenerate the lockfile locally:
482
483 1. Run `pnpm install` locally to update the lockfile.
484 2. Commit the updated `pnpm-lock.yaml`.
485 3. Push the changes to trigger a new deployment.
486
487 ---
488
489 ## Storefront: Cannot Find Module @opennextjs/cloudflare
490
491 If your storefront build fails with an error similar to:
492
493 ```bash
494 Cannot find module '@opennextjs/cloudflare/overrides/...'
495 ```
496
497 This error occurs when your storefront's `tsconfig.json` uses the legacy `moduleResolution: "node"` setting. The `@opennextjs/cloudflare` package uses subpath exports, which the `node` resolution mode cannot resolve.
498
499 ### Fix the moduleResolution Setting
500
501 Open your storefront's `tsconfig.json` and update `compilerOptions.moduleResolution` to `bundler` (recommended for Next.js 13+), or to `node16`/`nodenext`:
502
503 ```json title="apps/storefront/tsconfig.json"
504 {
505 "compilerOptions": {
506 "moduleResolution": "bundler"
507 }
508 }
509 ```
510
511 After updating the file, commit the change and push to trigger a new deployment.
512
513 ---
514
515 ## Storefront: opennextjs-cloudflare Not Found with pnpm 12
516
517 If your storefront uses pnpm 12 and its build fails with an error similar to:
518
519 ```bash
520 opennextjs-cloudflare: not found
521 ```
522
523 This error occurs because the Cloud storefront build installs the `@opennextjs/cloudflare` adapter with the `pnpm add --save` command. pnpm 12 removed the `--save` flag, so the adapter isn't installed and the build can't find the `opennextjs-cloudflare` binary.
524
525 ### Use pnpm 11 for Storefront Builds
526
527 Until Cloud supports pnpm 12 for storefront builds, use pnpm 11 in your monorepo. Set the `packageManager` field in your root `package.json` to a pnpm 11 version, such as `11.26.0`:
528
529 ```json title="package.json"
530 {
531 "packageManager": "pnpm@11.26.0"
532 }
533 ```
534
535 Then, run `pnpm install` locally with pnpm 11 to regenerate the `pnpm-lock.yaml` file, commit the changes, and push to trigger a new deployment.
536
537 ---
538
539 ## Next.js 15: 404 Prerender Error with Async Layouts
540
541 If your Next.js 15 storefront build fails during static prerendering with an error similar to:
542
543 ```bash
544 Error: React error #31 on /404
545 ```
546
547 This occurs when your `not-found.tsx` file inherits a parent layout that performs async data fetches, such as `retrieveCustomer` or `retrieveCart`. During static prerendering, Next.js 15 attempts to pre-render the `/404` route using the parent layout, which triggers the async data fetches in a context where they are not supported, causing a React error.
548
549 ### Fix the 404 Prerender Error
550
551 Add the following export to your `not-found.tsx` file to opt out of static prerendering and force the page to render dynamically at request time:
552
553 ```ts title="app/not-found.tsx"
554 export const dynamic = "force-dynamic"
555 ```
556
557 After adding this export, commit the change and push to trigger a new deployment.
558
559 ---
560
561 ## Storefront Prerender Error from React Version Mismatch in Monorepos
562
563 If your storefront build fails while prerendering error pages, such as `/404` or `/500`, with an error similar to the following, your monorepo may install more than one version of React:
564
565 ```bash
566 Error: Minified React error #31; visit
567 https://react.dev/errors/31?args[]=object%20with%20keys
568 ```
569
570 This happens when the root `package.json` and the storefront's `package.json` require different major versions of React. For example, the root `package.json` has React 18 in its `devDependencies`, while the storefront requires React 19. The storefront then renders with a mix of React 18 and React 19 packages, which fails during prerendering.
571
572 Type overrides can hide this mismatch. For example, if your root `package.json` forces `@types/react` to version 19 with pnpm `overrides`, type checking passes even though React 18 is still installed at runtime.
573
574 ### Detect the React Version Mismatch
575
576 Compare the versions of `react`, `react-dom`, `@types/react`, and `@types/react-dom` in your root `package.json` and in your storefront's `package.json`. Also check the `overrides` or `resolutions` fields in your root `package.json`.
577
578 Then, list the installed React versions from the storefront's directory. For example, with pnpm:
579
580 ```bash
581 pnpm why react react-dom
582 ```
583
584 If the output shows more than one major version of `react` or `react-dom`, your monorepo has a React version mismatch.
585
586 ### Fix the React Version Mismatch
587
588 Align React to the version that your storefront requires across all `package.json` files in your monorepo:
589
590 1. Update or remove `react` and `react-dom` in your root `package.json` so they match the storefront's versions. If the root package doesn't use React, remove them.
591 2. Make sure any `overrides` or `resolutions` for `@types/react` and `@types/react-dom` match the installed React version.
592 3. Run your package manager's install command locally to update the lockfile.
593 4. Run the storefront's `build` script locally to confirm the build succeeds.
594 5. Commit the updated `package.json` files and lockfile, then push to trigger a new deployment.
595
596 ---
597
598 ## Next.js 16 Middlewares Not Supported on Cloud
599
600 If you're using a Next.js 16 storefront with a middleware, also known as proxy, your build will fail with the following error:
601
602 ```bash
603 ERROR Node.js middleware is not currently supported. Consider switching to Edge Middleware.
604 ```
605
606 This is because Cloud does not currently support Node.js middlewares in Next.js 16. You can either:
607
608 1. Remove the middleware from your Next.js 16 storefront and redeploy.
609 2. Downgrade your storefront to Next.js 15, which does not have this limitation.
610
611 ---
612
613 ## Next.js Turbopack Workspace Root Error in Monorepos
614
615 If your Next.js 16+ storefront build fails with the following error:
616
617 ```bash
618 Error: Next.js inferred your workspace root, but it may not be correct.
619 We couldn't find the Next.js package (next/package.json) from the project directory
620 ```
621
622 This occurs in monorepo setups where the storefront is in a subdirectory (for example, `/storefront`) but `node_modules` is installed at the monorepo root. Turbopack's default workspace inference looks for `next/package.json` relative to the storefront directory, but the package is installed at the monorepo root.
623
624 ### Fix Turbopack Workspace Root
625
626 Set the `turbopack.root` option in your `next.config.ts` to point to the monorepo root:
627
628 ```ts title="apps/storefront/next.config.ts"
629 import path from "path"
630 import type { NextConfig } from "next"
631
632 const nextConfig: NextConfig = {
633 turbopack: {
634 root: path.join(__dirname, ".."),
635 },
636 }
637
638 export default nextConfig
639 ```
640
641 Replace `".."` with the relative path from your storefront directory to the monorepo root. Commit the updated `next.config.ts` and push to trigger a new deployment.
642
643 ---
644
645 ## Missing Root Files in Turborepo Monorepo Builds (TS5083)
646
647 If your `turbo` monorepo build fails with an error similar to the following, but succeeds locally, a file at the root of your monorepo isn't available during the build:
648
649 ```bash
650 error TS5083: Cannot read file '/tsconfig.base.json'.
651 ```
652
653 Medusa prunes `turbo` monorepos down to the package it's building. The pruned output only includes the root `package.json`, the lockfile, `pnpm-workspace.yaml`, `turbo.json`, `.gitignore`, `.npmrc`, and the source code of the target package along with the workspace packages it depends on. So, a shared root file, such as a `tsconfig.base.json` file that other packages reference with `extends`, isn't copied into the build.
654
655 ### Fix Missing Root Files
656
657 Move the shared file into a workspace package, then add that package as a dependency of your Medusa application or storefront. Medusa then includes the file in the build, since it builds the target package along with the workspace packages it depends on.
658
659 For files that your Medusa application needs at runtime, such as JSON files or fonts, keep them within your Medusa application and copy them to the `.medusa/server` directory as part of your `build` script. Learn more in the [Built Assets](!docs!/learn/build#built-assets) documentation.
660
661 ---
662
663 ## npm Cache Errors During Build
664
665 If your build fails with an error similar to:
666
667 ```bash
668 npm error code EEXIST
669 npm error syscall open
670 npm error path /root/.npm/_cacache/tmp/...
671 npm error errno -17
672 npm error EEXIST: file already exists, open '/root/.npm/_cacache/tmp/...'
673 ```
674
675 This is a transient npm cache corruption or a race condition in Docker's cache mount. The build environment's npm cache becomes temporarily inconsistent, causing `npm ci` to fail when writing temporary files.
676
677 ### Resolve npm Cache Errors
678
679 Retry the build. The error is transient and the build typically succeeds on the second attempt.
680
681 To retry a deployment from the Cloud dashboard:
682
683 1. If you're in a different organization, [switch to the organization](../../organizations/page.mdx#switch-organization).
684 2. Click **Projects** in the sidebar and select the project that contains the failed deployment.
685 3. Click **Deployments** in the sidebar under the project.
686 4. Find the failed deployment and click the <InlineIcon Icon={EllipsisHorizontal} alt="three-dots" /> button to open the deployment actions menu.
687 5. Click **Redeploy** to trigger a new build.
688
689 <Note>
690
691 If the error persists across two or three consecutive builds, contact support to clear the npm cache for your project.
692
693 </Note>
694
695 ---
696
697 ## Database Connection Failures
698
699 If your deployment fails with a database connection error such as `KnexTimeoutError` or `Pg connection failed to connect to the database`, the most common cause is a missing or misconfigured `DATABASE_URL` environment variable.
700
701 <Note>
702
703 Medusa automatically provisions and manages the database for each environment on Cloud. You do not need to create or configure a database yourself. The `DATABASE_URL` is set automatically by Cloud when your environment is created.
704
705 </Note>
706
707 ---
708
709 ## Custom start Script Not Executed on Cloud
710
711 Cloud starts your Medusa application by invoking `medusa start` directly. It does not use the `start` script defined in your `package.json`. This means that any custom logic you place in your `package.json` `start` script, such as environment checks, maintenance-mode toggles, or initialization commands, is not executed on Cloud.
712
713 ### Use Loaders for Custom Initialization
714
715 To run custom initialization logic when your Medusa application starts on Cloud, use [loaders](!docs!/learn/fundamentals/modules/loaders). Loaders are executed by Medusa as part of its startup process regardless of how the application is started.
716
717 For example, you can create a loader that checks an environment variable to enable maintenance mode or run any one-time setup logic:
718
719 ```ts title="src/loaders/maintenance.ts"
720 import { MedusaContainer } from "@medusajs/framework/types"
721 import {
722 ContainerRegistrationKeys,
723 } from "@medusajs/framework/utils"
724
725 export default async function maintenanceLoader(
726 container: MedusaContainer
727 ) {
728 if (process.env.MAINTENANCE_MODE === "true") {
729 const logger = container.resolve(
730 ContainerRegistrationKeys.LOGGER
731 )
732 logger.info("Maintenance mode is enabled.")
733 }
734 }
735 ```
736
737 ### Reserved Cloud Environment Variables
738
739 Cloud injects the following environment variables into every environment automatically:
740
741 - `MEDUSA_CLOUD_PROJECT_HANDLE`: The handle of your Cloud project.
742 - `MEDUSA_CLOUD_ENVIRONMENT_HANDLE`: The handle of the current Cloud environment.
743
744 You can read these variables inside your loaders to apply environment-specific logic.
745
746 ---
747
748 ## Troubleshooting Other Cloud Deployment Issues
749
750 To troubleshoot other Cloud deployment issues, you can:
751
752 - [Check the Cloud status page](../../status/page.mdx) for ongoing Cloud incidents.
753 - [Refer to Medusa's troubleshooting guides](!resources!/troubleshooting).
754 - Contact support for help.