esm: improve error when calling import.meta.resolve from data: URL

PR-URL: https://github.com/nodejs/node/pull/49516
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Antoine du Hamel authored and GitHub committed 2024-01-31 23:22:18 +01:00
1 parent 39d3f4215b
commit 3fbe1579ce
4 files changed
+75 -11

No files matched your search

+22
View File
@@ -2959,6 +2959,26 @@ import 'package-name'; // supported
`import` with URL schemes other than `file` and `data` is unsupported.
<a id="ERR_UNSUPPORTED_RESOLVE_REQUEST"></a>
### `ERR_UNSUPPORTED_RESOLVE_REQUEST`
An attempt was made to resolve an invalid module referrer. This can happen when
importing or calling `import.meta.resolve()` with either:
* a bare specifier that is not a builtin module from a module whose URL scheme
is not `file`.
* a [relative URL][] from a module whose URL scheme is not a [special scheme][].
```mjs
try {
// Trying to import the package 'bare-specifier' from a `data:` URL module:
await import('data:text/javascript,import "bare-specifier"');
} catch (e) {
console.log(e.code); // ERR_UNSUPPORTED_RESOLVE_REQUEST
}
```
<a id="ERR_USE_AFTER_CLOSE"></a>
### `ERR_USE_AFTER_CLOSE`
@@ -3710,7 +3730,9 @@ The native call from `process.cpuUsage` could not be processed.
[event emitter-based]: events.md#class-eventemitter
[file descriptors]: https://en.wikipedia.org/wiki/File_descriptor
[policy]: permissions.md#policies
[relative URL]: https://url.spec.whatwg.org/#relative-url-string
[self-reference a package using its name]: packages.md#self-referencing-a-package-using-its-name
[special scheme]: https://url.spec.whatwg.org/#special-scheme
[stream-based]: stream.md
[syscall]: https://man7.org/linux/man-pages/man2/syscalls.2.html
[try-catch]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch