@@ -807,9 +807,9 @@ To include an ES module into CommonJS, use [`import()`][].
807
807
808
808
### ` import` statements
809
809
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()` ][].
813
813
814
814
` import` statements are permitted only in ES modules . For similar functionality
815
815
in CommonJS, see [` import()` ][].
@@ -819,23 +819,22 @@ can either be an URL-style relative path like `'./file.mjs'` or a package name
819
819
like ` 'fs'` .
820
820
821
821
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"` .
823
825
824
826
` ` ` js
825
827
import { sin, cos } from 'geometry/trigonometry-functions.mjs';
826
828
` ` `
827
829
828
- > Currently only the “default export ” is 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 export ” is 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
+ ` ` `
839
838
840
839
### ` import()` expressions
841
840
@@ -1366,6 +1365,7 @@ success!
1366
1365
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
1367
1366
[Terminology]: #esm_terminology
1368
1367
[WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script
1368
+ [` " exports" ` field]: #esm_package_exports
1369
1369
[` data: ` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
1370
1370
[` esm` ]: https://github.com/standard-things/esm#readme
1371
1371
[` export ` ]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
0 commit comments