Skip to content

Commit f92df33

Browse files
aldeedMylesBorins
authored andcommitted
doc: import clarifications with links to MDN
PR-URL: nodejs#31479 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Myles Borins <[email protected]>
1 parent eeccd52 commit f92df33

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

doc/api/esm.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -912,17 +912,14 @@ import packageMain from 'commonjs-package'; // Works
912912
import { method } from 'commonjs-package'; // Errors
913913
```
914914

915+
It is also possible to
916+
[import an ES or CommonJS module for its side effects only][].
917+
915918
### `import()` expressions
916919

917-
Dynamic `import()` is supported in both CommonJS and ES modules. It can be used
920+
[Dynamic `import()`][] is supported in both CommonJS and ES modules. It can be used
918921
to include ES module files from CommonJS code.
919922

920-
```js
921-
(async () => {
922-
await import('./my-app.mjs');
923-
})();
924-
```
925-
926923
## CommonJS, JSON, and Native Modules
927924

928925
CommonJS, JSON, and Native modules can be used with
@@ -1716,6 +1713,7 @@ success!
17161713
[Babel]: https://babeljs.io/
17171714
[CommonJS]: modules.html
17181715
[Conditional Exports]: #esm_conditional_exports
1716+
[Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports
17191717
[ECMAScript-modules implementation]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
17201718
[ES Module Integration Proposal for Web Assembly]: https://github.com/webassembly/esm-integration
17211719
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
@@ -1725,13 +1723,14 @@ success!
17251723
[`esm`]: https://github.com/standard-things/esm#readme
17261724
[`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
17271725
[`getFormat` hook]: #esm_code_getformat_code_hook
1728-
[`import()`]: #esm_import-expressions
1726+
[`import()`]: #esm_import_expressions
17291727
[`import.meta.url`]: #esm_import_meta
17301728
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
17311729
[`module.createRequire()`]: modules.html#modules_module_createrequire_filename
17321730
[`module.syncBuiltinESMExports()`]: modules.html#modules_module_syncbuiltinesmexports
17331731
[`transformSource` hook]: #esm_code_transformsource_code_hook
17341732
[dynamic instantiate hook]: #esm_code_dynamicinstantiate_code_hook
1733+
[import an ES or CommonJS module for its side effects only]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Import_a_module_for_its_side_effects_only
17351734
[special scheme]: https://url.spec.whatwg.org/#special-scheme
17361735
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
17371736
[the dual CommonJS/ES module packages section]: #esm_dual_commonjs_es_module_packages

0 commit comments

Comments
 (0)