mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
esm: avoid throw when module specifier is not url
This particular exception is responsible for a lot of overhead when debugging with large esm codebases with VS Code and break on caught exceptions is enabled. VS Code silently suppresses this exception, but the mechanism it uses to do so is a bit slow so avoiding this common exception can speed up loading of esm code. In my scenario this saved over have of the startup run time (over 20 seconds). This should also make debugging without suppression of this exception more pleasant in other tools such as the Chrome dev tools when attached to NodeJs processes. PR-URL: https://github.com/nodejs/node/pull/61000 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
This commit is contained in:
committed by
GitHub
parent
20bf3287c2
commit
06bf489379
@@ -42,6 +42,7 @@ const {
|
||||
ERR_INVALID_MODULE_SPECIFIER,
|
||||
ERR_INVALID_PACKAGE_CONFIG,
|
||||
ERR_INVALID_PACKAGE_TARGET,
|
||||
ERR_INVALID_URL,
|
||||
ERR_MODULE_NOT_FOUND,
|
||||
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
||||
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
||||
@@ -846,12 +847,13 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
||||
} else if (protocol === 'file:' && specifier[0] === '#') {
|
||||
resolved = packageImportsResolve(specifier, base, conditions);
|
||||
} else {
|
||||
try {
|
||||
resolved = new URL(specifier);
|
||||
} catch (cause) {
|
||||
const url = URLParse(specifier);
|
||||
if (url !== null) {
|
||||
resolved = url;
|
||||
} else {
|
||||
if (isData && !BuiltinModule.canBeRequiredWithoutScheme(specifier)) {
|
||||
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
||||
setOwnProperty(error, 'cause', cause);
|
||||
setOwnProperty(error, 'cause', new ERR_INVALID_URL(specifier));
|
||||
throw error;
|
||||
}
|
||||
resolved = packageResolve(specifier, base, conditions);
|
||||
|
||||
Reference in New Issue
Block a user