Skip to content

module: deprecate trailing slash pattern mappings

This PR deprecates the ability for pattern mappings to be able to resolve import specifiers ending in / like import('pkg/subpath/'), with a new deprecation warning and message.

The primary motivation here is that the import maps specification does not support trailing / mappings resolving.

For example:

<!doctype html>
<script type="importmap">
{
  "imports": {
    "pkg/subpath/": "/pkg/index.js"
  }
}
</script>
<script type="module">
import 'pkg/subpath/';
</script>

will give the browser console error:

Ignored an import map value of "pkg/subpath/": Since specifierKey ended in a slash, so must the address: /pkg/index.js

See https://github.com/WICG/import-maps/issues/244 for more background here.

Since we deprecated folder subpaths, there are no common patterns of trailing / usage yet. It is only with the introduction of pattern trailers in https://github.com/nodejs/node/pull/39635 that it is now easy to define maps like:

{
  "exports": {
    "./*/": "./*/index.js"
  }
}

to support import('pkg/asdf/') resolving to pkg/asdf/index.js for any name.

The risk is that users start defining packages like this and then these packages will never be supportable in import maps environments. By deprecating this now we can avoid this outcome.

Merge request reports

Loading