Skip to content

Commit 6ac1b13

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 549a58e commit 6ac1b13

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
@@ -807,9 +807,9 @@ To include an ES module into CommonJS, use [`import()`][].
807807

808808
### `import` statements
809809

810-
An `import` statement can reference an ES module, a CommonJS module, or JSON.
811-
Other file types such as Native modules are not supported. For those,
812-
use [`module.createRequire()`][].
810+
An `import` statement can reference an ES module or a CommonJS module. Other
811+
file types such as JSON or Native modules are not supported. For those, use
812+
[`module.createRequire()`][].
813813

814814
`import` statements are permitted only in ES modules. For similar functionality
815815
in CommonJS, see [`import()`][].
@@ -819,23 +819,22 @@ can either be an URL-style relative path like `'./file.mjs'` or a package name
819819
like `'fs'`.
820820

821821
Like in CommonJS, files within packages can be accessed by appending a path to
822-
the package name.
822+
the package name; unless the package’s `package.json` contains an [`"exports"`
823+
field][], in which case files within packages need to be accessed via the path
824+
defined in `"exports"`.
823825

824826
```js
825827
import { sin, cos } from 'geometry/trigonometry-functions.mjs';
826828
```
827829

828-
> Currently only the “default exportis supported for CommonJS files or
829-
> packages:
830-
>
831-
> <!-- eslint-disable no-duplicate-imports -->
832-
> ```js
833-
> import packageMain from 'commonjs-package'; // Works
834-
>
835-
> import { method } from 'commonjs-package'; // Errors
836-
> ```
837-
>
838-
> There are ongoing efforts to make the latter code possible.
830+
Only the “default exportis supported for CommonJS files or packages:
831+
832+
<!-- eslint-disable no-duplicate-imports -->
833+
```js
834+
import packageMain from 'commonjs-package'; // Works
835+
836+
import { method } from 'commonjs-package'; // Errors
837+
```
839838

840839
### `import()` expressions
841840

@@ -1366,6 +1365,7 @@ success!
13661365
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
13671366
[Terminology]: #esm_terminology
13681367
[WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script
1368+
[`"exports"` field]: #esm_package_exports
13691369
[`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
13701370
[`esm`]: https://github.com/standard-things/esm#readme
13711371
[`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

0 commit comments

Comments
 (0)