diff --git a/doc/api/esm.md b/doc/api/esm.md index d1215b3caf5b..98e7b5014154 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -189,7 +189,7 @@ typically configured server. ES modules are resolved and cached as URLs. This means that special characters must be [percent-encoded][], such as `#` with `%23` and `?` with `%3F`. -`file:`, `node:`, and `data:` URL schemes are supported. A specifier like +`file:`, `node:`, `data:`, and `blob:` URL schemes are supported. A specifier like `'https://example.com/app.js'` is not supported natively in Node.js unless using a [custom HTTPS loader][]. @@ -231,6 +231,36 @@ and [absolute specifiers][Terminology]. Resolving from `data:text/javascript,import "./foo";` fails to resolve because there is no concept of relative resolution for `data:` URLs. +#### `blob:` imports + + + +> Stability: 1 - Experimental + +`blob:` URLs are supported for importing with the following MIME types: + +* `text/javascript` for ES modules +* `application/json` for JSON +* `application/wasm` for Wasm + +Blob URLs are registered within the current thread. Loaders will not be +able to resolve Blob URLs created from the main thread. + +```mjs +import { Blob } from 'node:buffer'; + +const mjs = new Blob(['export "Hello, World!"'], { type: 'text/javascript' }); +await import(URL.createObjectURL(mjs)); + +const json = new Blob(['{}'], { type: 'application/json' }); +await import(URL.createObjectURL(json), { with: { type: 'json' } }); + +const wasm = new Blob(['WASM Data'], { type: 'application/wasm' }); +await import(URL.createObjectURL(wasm)); +``` + #### `node:` imports