Skip to content

Commit 6541016

Browse files
committed
Update docs for native ESM in TypeScript
The recommended setup for Node.js projects is to set both `module` and `moduleResolution` to `nodendext`. With pulumi/pulumi#19980 we no longe rneed to manually set the `—loader` argument.
1 parent 9b6c932 commit 6541016

File tree

1 file changed

+8
-5
lines changed
  • content/docs/iac/languages-sdks/javascript

1 file changed

+8
-5
lines changed

content/docs/iac/languages-sdks/javascript/_index.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,33 +223,36 @@ If you wish to instead use [ESM](https://nodejs.org/api/esm.html) natively, you
223223
}
224224
```
225225

226-
Your `tsconfig.json` file should also be updated to ensure that TypeScript outputs ESM, by setting the [`module`](https://www.typescriptlang.org/tsconfig/#module) field to `ESNext`, or one of `ES2015/ES6/ES2020/ES2022`.
226+
Your `tsconfig.json` file should also be updated to ensure that TypeScript outputs ESM, by setting the [`module`](https://www.typescriptlang.org/tsconfig/#module) and [`moduleResolution`](https://www.typescriptlang.org/tsconfig/#moduleResolution) fields to `nodenext`.
227227

228228
```json
229229
{
230230
"compilerOptions": {
231231
...
232-
"module": "ESNext",
232+
"module": "nodenext",
233+
"moduleResolution": "nodenext",
233234
...
234235
}
235236
}
236237
```
237238

238-
Install a recent version of `ts-node` to use its [ESM loader](https://typestrong.org/ts-node/docs/imports#native-ecmascript-modules).
239+
Install a recent version of `typescript` and `ts-node`.
239240

240241
```bash
242+
npm isntall typescript@^5
241243
npm install ts-node@^10
242244
```
243245

244-
Lastly, you need to instruct Pulumi to use the `ts-node/esm` loader by setting the `nodeargs` option in the [`runtime`](https://www.pulumi.com/docs/iac/concepts/projects/project-file/#runtime-options) options in `Pulumi.yaml`.
245-
246+
{{< notes >}}
247+
When using a version of `@pulumi/pulumi` older than 3.182.0, you need to instruct Pulumi to use the `ts-node/esm` loader by setting the `nodeargs` option in the [`runtime`](https://www.pulumi.com/docs/iac/concepts/projects/project-file/#runtime-options) options in `Pulumi.yaml`. More recent versions automatically configure this.
246248
```yaml
247249
name: project-using-native-esm
248250
runtime:
249251
name: nodejs
250252
options:
251253
nodeargs: "--loader ts-node/esm --no-warnings"
252254
```
255+
{{< /notes >}}
253256

254257
## Using ESM only modules with CommonJS Pulumi templates
255258

0 commit comments

Comments
 (0)