diff options
author | Geoffrey Booth <webmaster@geoffreybooth.com> | 2019-11-16 23:35:16 -0800 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-11-17 01:08:09 -0800 |
commit | 5c576168ee409cd2a398a0e504aeffc3a10a9aed (patch) | |
tree | 5e9a0bd4c54f72dd6b9def132063b9e6b6df9b44 /doc/api/esm.md | |
parent | 250a9956561de336bc408d7ed184ba3a2610e272 (diff) | |
download | android-node-v8-5c576168ee409cd2a398a0e504aeffc3a10a9aed.tar.gz android-node-v8-5c576168ee409cd2a398a0e504aeffc3a10a9aed.tar.bz2 android-node-v8-5c576168ee409cd2a398a0e504aeffc3a10a9aed.zip |
doc: update outdated commonjs compat info
PR-URL: https://github.com/nodejs/node/pull/30512
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'doc/api/esm.md')
-rw-r--r-- | doc/api/esm.md | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md index 0aec8952cf..caaecaa0b4 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -834,9 +834,9 @@ To include an ES module into CommonJS, use [`import()`][]. ### <code>import</code> statements -An `import` statement can reference an ES module, a CommonJS module, or JSON. -Other file types such as Native modules are not supported. For those, -use [`module.createRequire()`][]. +An `import` statement can reference an ES module or a CommonJS module. Other +file types such as JSON or Native modules are not supported. For those, use +[`module.createRequire()`][]. `import` statements are permitted only in ES modules. For similar functionality in CommonJS, see [`import()`][]. @@ -846,23 +846,22 @@ can either be an URL-style relative path like `'./file.mjs'` or a package name like `'fs'`. Like in CommonJS, files within packages can be accessed by appending a path to -the package name. +the package name; unless the package’s `package.json` contains an [`"exports"` +field][], in which case files within packages need to be accessed via the path +defined in `"exports"`. ```js import { sin, cos } from 'geometry/trigonometry-functions.mjs'; ``` -> Currently only the “default export” is supported for CommonJS files or -> packages: -> -> <!-- eslint-disable no-duplicate-imports --> -> ```js -> import packageMain from 'commonjs-package'; // Works -> -> import { method } from 'commonjs-package'; // Errors -> ``` -> -> There are ongoing efforts to make the latter code possible. +Only the “default export” is supported for CommonJS files or packages: + +<!-- eslint-disable no-duplicate-imports --> +```js +import packageMain from 'commonjs-package'; // Works + +import { method } from 'commonjs-package'; // Errors +``` ### <code>import()</code> expressions @@ -1394,6 +1393,7 @@ success! [Package Exports]: #esm_package_exports [Terminology]: #esm_terminology [WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script +[`"exports"` field]: #esm_package_exports [`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs [`esm`]: https://github.com/standard-things/esm#readme [`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export |