Skip to content

Commit fe147be

Browse files
chore: sync docs/release-docs-staging with develop
2 parents 738883c + bd83bab commit fe147be

7 files changed

Lines changed: 109 additions & 3 deletions

File tree

www/apps/book/public/llms-full.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19053,7 +19053,7 @@ In this chapter, you’ll learn about Query and how to use it to fetch data from
1905319053

1905419054
Query fetches data across modules. It's a set of methods registered in the Medusa container under the `query` key.
1905519055

19056-
In all resources that can access the [Medusa Container](undefined/learn/fundamentals/medusa-container), such as API routes or workflows, you can resolve Query to fetch data across custom modules and Medusa's Commerce Modules.
19056+
In all resources that can access the [Medusa Container](https://docs.medusajs.com/learn/fundamentals/medusa-container/index.html.md), such as API routes or workflows, you can resolve Query to fetch data across custom modules and Medusa's Commerce Modules.
1905719057

1905819058
Prefer Query for read operations (list and retrieve) in API routes. It integrates with the [`validateAndTransformQuery` middleware](#request-query-configurations) and resolves cross-module links automatically.
1905919059

@@ -41061,7 +41061,7 @@ Account holder creation is idempotent per customer. When the Payment Module call
4106141061

4106241062
Do not compensate account holder creation with a provider-side delete in your custom workflows. If you call `deleteAccountHolder` in a compensation step, a subsequent retry will ask the provider to create the account holder again. However, the provider may replay the original creation response for the same idempotency key, returning the already-deleted object. This results in an account holder in Medusa that points to a deleted provider-side customer, causing saved payment method flows to fail until the provider's idempotency window expires.
4106341063

41064-
The built-in [createPaymentSessionsWorkflow](undefined/references/medusa-workflows/createPaymentSessionsWorkflow) accounts for this behavior by calling the `createPaymentAccountHolderStep` with `noCompensation: true`. This means the step is not compensated when the workflow rolls back. If the account holder was already linked to the customer before the workflow ran, the step returns the existing account holder and skips provider-side creation entirely.
41064+
The built-in [createPaymentSessionsWorkflow](https://docs.medusajs.com/references/medusa-workflows/createPaymentSessionsWorkflow/index.html.md) accounts for this behavior by calling the `createPaymentAccountHolderStep` with `noCompensation: true`. This means the step is not compensated when the workflow rolls back. If the account holder was already linked to the customer before the workflow ran, the step returns the existing account holder and skips provider-side creation entirely.
4106541065

4106641066
If you build a custom workflow that creates account holders, use the same `noCompensation: true` config on `createPaymentAccountHolderStep`, or omit a compensation function that calls `deleteAccountHolder` on the provider.
4106741067

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
export const metadata = {
2+
title: `Unexpected token 'export' Error`,
3+
}
4+
5+
# {metadata.title}
6+
7+
You may run into the following error when you run migrations or start the Medusa application from the `.medusa/server` directory, such as during deployment:
8+
9+
```bash
10+
SyntaxError: Unexpected token 'export'
11+
```
12+
13+
The error points to a compiled JavaScript file in the `.medusa/server` directory, such as `.medusa/server/medusa-config.js` or a file under `.medusa/server/src`.
14+
15+
## Why this Error Occurred
16+
17+
The Medusa application loads your files, including the configuration file, migrations, API routes, and subscribers, as CommonJS modules at runtime.
18+
19+
The [build](!docs!/learn/build) command compiles your TypeScript files using the `module` option in your `tsconfig.json` file. If you set that option to an ES module format, such as `ESNext` or `ES2022`, the compiled files keep the `export` and `import` keywords instead of using CommonJS syntax.
20+
21+
Node.js then treats every `.js` file as CommonJS, since the `package.json` file of a Medusa application doesn't have a `"type": "module"` field. So, Node.js fails to parse the `export` keyword and throws the above error.
22+
23+
---
24+
25+
## How to Diagnose it
26+
27+
1. Open the `tsconfig.json` file at the root of your Medusa application and check the `module` and `moduleResolution` options. An ES module format, such as `ESNext`, `ES2020`, or `ES2022`, causes this error.
28+
2. Open the `package.json` file at the root of your Medusa application and check whether it has a `"type": "module"` field. If it does, remove it using the steps in the next section.
29+
3. Open the file mentioned in the error message under `.medusa/server` and check whether it starts with `import` or contains `export` statements. If it does, the compiled output uses an ES module format.
30+
31+
---
32+
33+
## How to Fix it
34+
35+
To fix this error, change the `module` and `moduleResolution` options in your `tsconfig.json` file to `Node16`, which is the configuration that Medusa applications use:
36+
37+
```json title="tsconfig.json"
38+
{
39+
"compilerOptions": {
40+
"module": "Node16",
41+
"moduleResolution": "Node16"
42+
}
43+
}
44+
```
45+
46+
Then, if your `package.json` file has a `"type": "module"` field, remove it:
47+
48+
```json title="package.json"
49+
{
50+
"type": "module"
51+
}
52+
```
53+
54+
<Note type="warning">
55+
56+
Don't add a `"type": "module"` field to your `package.json` file to resolve this error. It changes how Node.js interprets every file in your project, and Medusa applications don't support ES modules. Learn more about this field in the [Node.js documentation](https://nodejs.org/api/packages.html#type).
57+
58+
</Note>
59+
60+
Finally, create the production build again:
61+
62+
```bash npx2yarn
63+
npx medusa build
64+
```
65+
66+
The compiled files now use CommonJS syntax, and you can run migrations and start the application as explained in the [build](!docs!/learn/build) documentation.
67+
68+
---
69+
70+
## Additional Resources
71+
72+
- [Build Medusa Application](!docs!/learn/build): Learn how to create a production build and start it.
73+
- [General Deployment](!docs!/learn/deployment/general): Learn the general steps to deploy a Medusa application.

www/apps/resources/generated/edit-dates.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7636,5 +7636,6 @@ export const generatedEditDates = {
76367636
"app/commerce-modules/order/transfer-to-guest/page.mdx": "2026-07-23T06:59:03.176Z",
76377637
"app/lint/rules/no-wildcard-with-specific-fields/page.mdx": "2026-07-23T07:05:02.983Z",
76387638
"app/lint/rules/use-query-context-utility/page.mdx": "2026-07-23T07:07:28.191Z",
7639-
"app/commerce-modules/settings/admin-widget-zones/page.mdx": "2026-07-23T12:47:37.342Z"
7639+
"app/commerce-modules/settings/admin-widget-zones/page.mdx": "2026-07-23T12:47:37.342Z",
7640+
"app/troubleshooting/esm-syntax-error/page.mdx": "2026-07-27T11:43:33.424Z"
76407641
}

www/apps/resources/generated/files-map.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,10 @@ export const filesMap = [
19551955
"filePath": "/www/apps/resources/app/troubleshooting/errors-installing-cli/page.mdx",
19561956
"pathname": "/troubleshooting/errors-installing-cli"
19571957
},
1958+
{
1959+
"filePath": "/www/apps/resources/app/troubleshooting/esm-syntax-error/page.mdx",
1960+
"pathname": "/troubleshooting/esm-syntax-error"
1961+
},
19581962
{
19591963
"filePath": "/www/apps/resources/app/troubleshooting/general-errors/page.mdx",
19601964
"pathname": "/troubleshooting/general-errors"

www/apps/resources/generated/generated-troubleshooting-sidebar.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ const generatedgeneratedTroubleshootingSidebarSidebar = {
6363
}
6464
]
6565
},
66+
{
67+
"loaded": true,
68+
"type": "category",
69+
"title": "Build and Deployment",
70+
"initialOpen": true,
71+
"children": [
72+
{
73+
"loaded": true,
74+
"type": "link",
75+
"path": "/troubleshooting/esm-syntax-error",
76+
"title": "Unexpected token 'export' Error",
77+
"children": []
78+
}
79+
]
80+
},
6681
{
6782
"loaded": true,
6883
"type": "category",

www/apps/resources/generated/sitemap-urls.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ export const sitemapUrls = [
488488
"/troubleshooting/eaddrinuse",
489489
"/troubleshooting/errors-after-upgrading",
490490
"/troubleshooting/errors-installing-cli",
491+
"/troubleshooting/esm-syntax-error",
491492
"/troubleshooting/general-errors",
492493
"/troubleshooting/medusa-admin/blocked-request",
493494
"/troubleshooting/medusa-admin/build-error",

www/apps/resources/sidebars/troubleshooting.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ export const troubleshootingSidebar = [
4747
},
4848
],
4949
},
50+
{
51+
type: "category",
52+
title: "Build and Deployment",
53+
initialOpen: true,
54+
children: [
55+
{
56+
type: "link",
57+
path: "/troubleshooting/esm-syntax-error",
58+
title: "Unexpected token 'export' Error",
59+
},
60+
],
61+
},
5062
{
5163
type: "category",
5264
title: "Framework",

0 commit comments

Comments
 (0)