diff --git a/doc/api/cli.md b/doc/api/cli.md index 9776a0f6efae7f..578f08d16f45e2 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -251,6 +251,14 @@ added: Enable experimental `import.meta.resolve()` support. +### `--experimental-import-non-javascript-without-assertion` + + +Enable experimental support importing non-JS modules without using an import +assertion. + ### `--experimental-json-modules` + +An import assertion has failed, preventing the specified module to be imported. + ### `ERR_FALSY_VALUE_REJECTION` @@ -1660,6 +1668,14 @@ for more information. An invalid HTTP token was supplied. + +### `ERR_INVALID_IMPORT_ASSERTION` + + +An import assertion is not supported by this version of Node.js. + ### `ERR_INVALID_IP_ADDRESS` @@ -1909,6 +1925,15 @@ strict compliance with the API specification (which in some cases may accept `func(undefined)` and `func()` are treated identically, and the [`ERR_INVALID_ARG_TYPE`][] error code may be used instead. + +### `ERR_MISSING_IMPORT_ASSERTION` + + +An attempt was made to impor without an assertion a module that requires a +specific import assertion to be loaded. + ### `ERR_MISSING_OPTION` diff --git a/doc/api/esm.md b/doc/api/esm.md index 32beab664dc885..3054aefafd6072 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -7,6 +7,9 @@ + +The [Import Assertions proposal][] adds an inline syntax for module import +statements to pass on more information alongside the module specifier. + +```js +import json from './foo.json' assert { type: "json" }; +await import('foo.json', { assert: { type: "json" } }); +``` + +Node.js supports the following `type` values: + +| `type` | Resolves to | +| -------- | ---------------- | +| `"json"` | [JSON modules][] | + ## Builtin modules [Core modules][] provide named exports of their public API. A @@ -518,9 +540,8 @@ same path. Assuming an `index.mjs` with - ```js -import packageConfig from './package.json'; +import packageConfig from './package.json' assert { type: 'json' }; ``` The `--experimental-json-modules` flag is needed for the module @@ -1351,6 +1372,8 @@ success! [Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports [ECMAScript Top-Level `await` proposal]: https://github.com/tc39/proposal-top-level-await/ [ES Module Integration Proposal for Web Assembly]: https://github.com/webassembly/esm-integration +[Import Assertions proposal]: https://github.com/tc39/proposal-import-assertions +[JSON modules]: #json-modules [Node.js Module Resolution Algorithm]: #resolver-algorithm-specification [Terminology]: #terminology [URL]: https://url.spec.whatwg.org/ diff --git a/doc/api/vm.md b/doc/api/vm.md index b7cde0e3b69381..d8470004f4ae66 100644 --- a/doc/api/vm.md +++ b/doc/api/vm.md @@ -54,6 +54,10 @@ executed in specific contexts. * `code` {string} JavaScript Module code to parse * `options` @@ -667,6 +680,8 @@ defined in the ECMAScript specification. `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. * `specifier` {string} specifier passed to `import()` * `module` {vm.Module} + * `import_assertions` {Object} The `"assert"` value passed to the + `optionExpression` optional parameter. * Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports. @@ -852,6 +867,10 @@ const vm = require('vm');