You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/api/esm.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -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 ESmodule, 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 ESmodule 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 inESmodules. 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” issupportedforCommonJSfilesor
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” issupportedforCommonJSfilesorpackages:
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
0 commit comments