Skip to content

Commit 41ca6bf

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 41ca6bf

File tree

1 file changed

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

1 file changed

+5
-13
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,34 +223,26 @@ 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-
```yaml
247-
name: project-using-native-esm
248-
runtime:
249-
name: nodejs
250-
options:
251-
nodeargs: "--loader ts-node/esm --no-warnings"
252-
```
253-
254246
## Using ESM only modules with CommonJS Pulumi templates
255247

256248
Older versions of Node.js do not support loading ESM modules using the `require` function (`require` is part of CommonJS, the default runtime targetted by TypeScript in the Pulumi templates). You may encounter an error like the following:

0 commit comments

Comments
 (0)