GeezerVison is showing github.com — doc: highlight module loading difference between import and require · nodejs/node@795f32b
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/esm.md +6Lines changed: 6 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -332,6 +332,12 @@ syncBuiltinESMExports(); |
332 | 332 | fs.readFileSync === readFileSync; |
333 | 333 | ``` |
334 | 334 |
|
| 335 | +> When importing built-in modules, all the named exports (i.e. properties of the module exports object) |
| 336 | +> are populated even if they are not individually accessed. |
| 337 | +> This can make initial imports of built-in modules slightly slower compared to loading them with |
| 338 | +> `require()` or `process.getBuiltinModule()`, where the module exports object is evaluated immediately, |
| 339 | +> but some of its properties may only be initialized when first accessed individually. |
| 340 | +
|
335 | 341 | ## `import()` expressions |
336 | 342 |
|
337 | 343 | [Dynamic `import()`][] provides an asynchronous way to import modules. It is |
|