| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -834,9 +834,9 @@ To include an ES module into CommonJS, use [`import()`][]. | |||
| 834 | 834 | ||
| 835 | 835 | ### <code>import</code> statements | |
| 836 | 836 | ||
| 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()`][]. | ||
| 840 | 840 | ||
| 841 | 841 | `import` statements are permitted only in ES modules. For similar functionality | |
| 842 | 842 | in CommonJS, see [`import()`][]. | |
@@ -846,23 +846,22 @@ can either be an URL-style relative path like `'./file.mjs'` or a package name | |||
| 846 | 846 | like `'fs'`. | |
| 847 | 847 | ||
| 848 | 848 | 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"`. | ||
| 850 | 852 | ||
| 851 | 853 | ```js | |
| 852 | 854 | import { sin, cos } from 'geometry/trigonometry-functions.mjs'; | |
| 853 | 855 | ``` | |
| 854 | 856 | ||
| 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 | + ``` | ||
| 866 | 865 | ||
| 867 | 866 | ### <code>import()</code> expressions | |
| 868 | 867 | ||
@@ -1394,6 +1393,7 @@ success! | |||
| 1394 | 1393 | [Package Exports]: #esm_package_exports | |
| 1395 | 1394 | [Terminology]: #esm_terminology | |
| 1396 | 1395 | [WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script | |
| 1396 | + [`"exports"` field]: #esm_package_exports | ||
| 1397 | 1397 | [`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | |
| 1398 | 1398 | [`esm`]: https://github.com/standard-things/esm#readme | |
| 1399 | 1399 | [`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export | |
| Back | FazBrowse Home | New Git URL |
0 commit comments