Skip to content

Commit

Permalink
Cover multiple import maps
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavweiss committed Jan 21, 2025
1 parent 4c16b7f commit 3e50a51
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions files/en-us/web/html/element/script/type/importmap/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ For more information, see the [Importing modules using import maps](/en-US/docs/

The `src`, `async`, `nomodule`, `defer`, `crossorigin`, `integrity`, and `referrerpolicy` attributes must not be specified.

Only the first import map in the document with an inline definition is processed; any additional import maps and external import maps are ignored.

### Exceptions

- `TypeError`
- : The import map definition is not a JSON object, the `importmap` key is defined but its value is not a JSON object, or the `scopes` key is defined but its value is not a JSON object.

Browsers generate console warnings for other cases where the import map JSON does not conform to the [import map](#import_map_json_representation) schema.

An [`error` event](/en-US/docs/Web/API/HTMLElement/error_event) is fired at script elements with `type="importmap"` that are not processed.
This might occur, for example, if module loading has already started when an import map is processed, or if multiple import maps are defined in the page.

## Description

When importing a [JavaScript module](/en-US/docs/Web/JavaScript/Guide/Modules), both the [`import` statement](/en-US/docs/Web/JavaScript/Reference/Statements/import) and [`import()` operator](/en-US/docs/Web/JavaScript/Reference/Operators/import) have a "module specifier" that indicates the module to be imported.
Expand Down Expand Up @@ -213,6 +208,18 @@ The import map must be a valid JSON object that can define any of the optional k

Note that the scope does not change how an address is resolved; relative addresses are always resolved to the import map base URL.

## Merging multiple import maps

<aside>This is supported is the latest versions of some browsers. In non-supporting browsers, a [polyfill](https://github.com/guybedford/es-module-shims) can be used to avoid issues related to module resolution.</aside>

Internally, browsers maintain a single global import map representation.

When an import map is registered, its contents are merged into the global import map.

Module specifiers in the registered map that were already resolved before are dropped. Future resolution of these specifiers will provide the same results as their previous resolution.

Module specifiers in the registered map that were already mapped to URLs in the global map are similarly dropped and their previous mapping prevails.

## Specifications

{{Specifications}}
Expand Down

0 comments on commit 3e50a51

Please sign in to comment.