Skip to content

Commit bd52689

Browse files
authored
docs: add missing package.json "type": "module" step to TypeScript install guide
The TypeScript setup section provides a tsconfig.json using "module": "nodenext" and demonstrates ESM import syntax in src/app.ts, but doesn't mention that package.json also needs "type": "module" set. Without it, TypeScript treats .ts files as CommonJS by default and throws ECMAScript imports and exports cannot be written in a CommonJS file under 'verbatimModuleSyntax'. (ts1295) when following the guide as written. This adds the missing step so the example works out of the box. Signed-off-by: Jameel Ahmad <jameelahmad221b@gmail.com>
1 parent f118e03 commit bd52689

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/content/docs/en/5x/starter/installing.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ for example `@types/cors` alongside `cors`.
5252

5353
</Alert>
5454

55+
Since the `tsconfig.json` below uses `"module": "nodenext"`, TypeScript determines whether each
56+
file is treated as an ES Module or CommonJS based on the `"type"` field in your `package.json`.
57+
Add `"type": "module"` to your `package.json` so that ES Module `import`/`export` syntax is
58+
recognized:
59+
60+
```json title="package.json"
61+
{
62+
"type": "module"
63+
}
64+
```
65+
66+
<Alert type="warning">
67+
68+
Without `"type": "module"`, TypeScript will treat `.ts` files as CommonJS and report an error like
69+
`ECMAScript imports and exports cannot be written in a CommonJS file under 'verbatimModuleSyntax'`
70+
when you use `import`/`export` syntax.
71+
72+
</Alert>
73+
5574
Add a `tsconfig.json`. These options mirror how Node.js runs TypeScript and make the compiler reject
5675
non-erasable syntax (such as `enum`s, namespaces, and parameter properties) that Node cannot strip:
5776

0 commit comments

Comments
 (0)