Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/content/docs/en/5x/starter/installing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ for example `@types/cors` alongside `cors`.

</Alert>

Since the `tsconfig.json` below uses `"module": "nodenext"`, TypeScript determines whether each
file is treated as an ES Module or CommonJS based on the `"type"` field in your `package.json`.
Recent versions of `npm init` set `"type": "commonjs"` by default, so change it to `"module"` so
that ES Module `import`/`export` syntax is recognized:

```bash
npm pkg set type=module
```

```json title="package.json"
{
"type": "module"
}
```

<Alert type="warning">

Without `"type": "module"`, TypeScript will treat `.ts` files as CommonJS and report an error like
`ECMAScript imports and exports cannot be written in a CommonJS file under 'verbatimModuleSyntax'`
when you use `import`/`export` syntax.

</Alert>

Add a `tsconfig.json`. These options mirror how Node.js runs TypeScript and make the compiler reject
non-erasable syntax (such as `enum`s, namespaces, and parameter properties) that Node cannot strip:

Expand Down
Loading