diff --git a/doc/api/errors.md b/doc/api/errors.md index a03b1f6fc2572a..89bf8b044eb573 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1108,6 +1108,14 @@ The JS execution context is not associated with a Node.js environment. This may occur when Node.js is used as an embedded library and some hooks for the JS engine are not set up properly. + +### `ERR_FAILED_IMPORT_ASSERTION` + + +An import assertion has failed, preventing the specified module to be imported. + ### `ERR_FALSY_VALUE_REJECTION` @@ -1659,6 +1667,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` diff --git a/doc/api/esm.md b/doc/api/esm.md index 9d7792441ca6fd..15158dcaca3031 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -5,6 +5,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 @@ -516,9 +538,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 @@ -1367,6 +1388,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 cff8c9b6e23bf3..2929dffa0d435f 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');