Skip to content

Commit 5c57616

Browse files
GeoffreyBoothMylesBorins
authored andcommitted
doc: update outdated commonjs compat info
PR-URL: #30512 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 250a995 commit 5c57616

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

doc/api/esm.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -834,9 +834,9 @@ To include an ES module into CommonJS, use [`import()`][].
834834
835835
### <code>import</code> statements
836836
837-
An `import` statement can reference an ES module, a CommonJS module, or JSON.
838-
Other file types such as Native modules are not supported. For those,
839-
use [`module.createRequire()`][].
837+
An `import` statement can reference an ES module or a CommonJS module. Other
838+
file types such as JSON or Native modules are not supported. For those, use
839+
[`module.createRequire()`][].
840840
841841
`import` statements are permitted only in ES modules. For similar functionality
842842
in CommonJS, see [`import()`][].
@@ -846,23 +846,22 @@ can either be an URL-style relative path like `'./file.mjs'` or a package name
846846
like `'fs'`.
847847
848848
Like in CommonJS, files within packages can be accessed by appending a path to
849-
the package name.
849+
the package name; unless the package’s `package.json` contains an [`"exports"`
850+
field][], in which case files within packages need to be accessed via the path
851+
defined in `"exports"`.
850852
851853
```js
852854
import { sin, cos } from 'geometry/trigonometry-functions.mjs';
853855
```
854856
855-
> Currently only the “default export” is supported for CommonJS files or
856-
> packages:
857-
>
858-
> <!-- eslint-disable no-duplicate-imports -->
859-
> ```js
860-
> import packageMain from 'commonjs-package'; // Works
861-
>
862-
> import { method } from 'commonjs-package'; // Errors
863-
> ```
864-
>
865-
> There are ongoing efforts to make the latter code possible.
857+
Only the “default export” is supported for CommonJS files or packages:
858+
859+
<!-- eslint-disable no-duplicate-imports -->
860+
```js
861+
import packageMain from 'commonjs-package'; // Works
862+
863+
import { method } from 'commonjs-package'; // Errors
864+
```
866865
867866
### <code>import()</code> expressions
868867
@@ -1394,6 +1393,7 @@ success!
13941393
[Package Exports]: #esm_package_exports
13951394
[Terminology]: #esm_terminology
13961395
[WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script
1396+
[`"exports"` field]: #esm_package_exports
13971397
[`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
13981398
[`esm`]: https://github.com/standard-things/esm#readme
13991399
[`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

0 commit comments

Comments
 (0)