Skip to content

Commit

Permalink
doc: import clarifications with links to MDN
Browse files Browse the repository at this point in the history
PR-URL: nodejs#31479
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
  • Loading branch information
aldeed authored and MylesBorins committed Apr 3, 2020
1 parent 07b77a3 commit 9da5813
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,17 +929,14 @@ import packageMain from 'commonjs-package'; // Works
import { method } from 'commonjs-package'; // Errors
```

It is also possible to
[import an ES or CommonJS module for its side effects only][].

### `import()` expressions

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

```js
(async () => {
await import('./my-app.mjs');
})();
```

## CommonJS, JSON, and Native Modules

CommonJS, JSON, and Native modules can be used with
Expand Down Expand Up @@ -1737,6 +1734,7 @@ success!
[Babel]: https://babeljs.io/
[CommonJS]: modules.html
[Conditional Exports]: #esm_conditional_exports
[Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports
[ECMAScript-modules implementation]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
[ES Module Integration Proposal for Web Assembly]: https://github.com/webassembly/esm-integration
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
Expand All @@ -1748,13 +1746,14 @@ success!
[`esm`]: https://github.com/standard-things/esm#readme
[`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
[`getFormat` hook]: #esm_code_getformat_code_hook
[`import()`]: #esm_import-expressions
[`import()`]: #esm_import_expressions
[`import.meta.url`]: #esm_import_meta
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
[`module.createRequire()`]: modules.html#modules_module_createrequire_filename
[`module.syncBuiltinESMExports()`]: modules.html#modules_module_syncbuiltinesmexports
[`transformSource` hook]: #esm_code_transformsource_code_hook
[dynamic instantiate hook]: #esm_code_dynamicinstantiate_code_hook
[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
[special scheme]: https://url.spec.whatwg.org/#special-scheme
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
[transpiler loader example]: #esm_transpiler_loader
Expand Down

0 comments on commit 9da5813

Please sign in to comment.