Skip to content

Commit d821b6a

Browse files
committed
docs: clarify that ESM is default now
1 parent fbabacd commit d821b6a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/views/docs/en/guides/developer-experience/using-esm.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ description: How to use ECMAScript Modules in functions
55
---
66

77
[AWS Lambdas support ES modules and top-level await](https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/). Architect adheres to Node.js conventions and the AWS implementation.
8-
Lambdas must use the `nodejs14.x` or greater runtime to leverage ESM.
98

109
## Example project
1110

12-
A working Architect project with each method for using ESM and CJS, can be found on GitHub: [`architect-examples/arc-example-esm-cjs`](https://github.com/architect-examples/arc-example-esm-cjs).
11+
A working Architect project with each method for using ESM and CJS can be found on GitHub: [`architect-examples/arc-example-esm-cjs`](https://github.com/architect-examples/arc-example-esm-cjs).
1312

14-
## CommonJS by default
13+
## ESM by default
1514

16-
Architect projects currently default to CommonJS. In the future, `arc init` and `arc create` may generate ESM functions by default. Architect will always support CJS so long as Node.js does.
15+
Architect projects default to ESM. Architect will always support CJS so long as Node.js does.
1716

18-
## ES Modules with `.mjs`
17+
## ESM with `.mjs`
1918

2019
The simplest way to start using ESM is to create JavaScript files with a `.mjs` extension. For example, no configuration is needed for the following shared helper and HTTP GET function to work as ES modules:
2120

@@ -26,7 +25,7 @@ export default function () {
2625
}
2726
```
2827

29-
The shared ESM file can be imported in any function. Remember, ES module import statements require the file extension.
28+
The shared ESM file can be imported in any function. Remember, ESM `import` statements require the file extension.
3029

3130
```javascript
3231
// ./src/http/get-index/index.mjs
@@ -37,9 +36,9 @@ export async function handler (event) {
3736
}
3837
```
3938

40-
## ES Modules with `package.json`
39+
## ESM with `package.json`
4140

42-
Alternatively, the `"type"` property of a function's package.json file can be set to `"module"` to declare the function is ESM. That function's handler file can then use a `.js` file extension:
41+
Alternatively, if you are using [manual per-function dependency management](dependency-management#manual-dependency-management), the `"type"` property of a function's `package.json` file can be set to `"module"` to declare the function is ESM. That function's handler file can then use a `.js` file extension:
4342

4443
```json
4544
// ./src/http/get-index/package.json
@@ -59,7 +58,7 @@ Alternatively, the `"type"` property of a function's package.json file can be se
5958
└── app.arc
6059
```
6160

62-
Declaring dependencies in a function's `package.json` will disable Lambda treeshaking for that function. This is true no matter the module type.
61+
Declaring dependencies in a function's `package.json` will disable [automated dependency treeshaking](dependency-management#automated-dependency-treeshaking) for that function. This is true no matter the module type.
6362

6463
> ℹ️ Setting `"type": "module"` in the project's root `package.json` will not affect function module types.
6564

0 commit comments

Comments
 (0)