[resolver] Do not throw on require()/import errors when they're caught (and import is an await target)

This commit is contained in:
Jarred Sumner
2021-12-04 03:26:14 -08:00
parent 1dc78ba4b7
commit b2fcc027a9
2 changed files with 62 additions and 53 deletions

View File

@@ -1625,11 +1625,13 @@ pub const Bundler = struct {
);
} else |err| {
if (comptime isDebug) {
Output.prettyErrorln("\n<r><red>{s}<r> on resolving \"{s}\" from \"{s}\"", .{
@errorName(err),
import_record.path.text,
file_path.text,
});
if (!import_record.handles_import_errors) {
Output.prettyErrorln("\n<r><red>{s}<r> on resolving \"{s}\" from \"{s}\"", .{
@errorName(err),
import_record.path.text,
file_path.text,
});
}
}
// Disable failing packages from being printed.
@@ -1640,37 +1642,39 @@ pub const Bundler = struct {
switch (err) {
error.ModuleNotFound => {
if (isPackagePath(import_record.path.text)) {
if (this.bundler.options.platform.isWebLike() and options.ExternalModules.isNodeBuiltin(import_record.path.text)) {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve Node.js builtin: \"{s}\".",
.{import_record.path.text},
import_record.kind,
);
if (!import_record.handles_import_errors) {
if (isPackagePath(import_record.path.text)) {
if (this.bundler.options.platform.isWebLike() and options.ExternalModules.isNodeBuiltin(import_record.path.text)) {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve Node.js builtin: \"{s}\".",
.{import_record.path.text},
import_record.kind,
);
} else {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve: \"{s}\". Maybe you need to \"npm install\" (or yarn/pnpm)?",
.{import_record.path.text},
import_record.kind,
);
}
} else {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve: \"{s}\". Maybe you need to \"npm install\" (or yarn/pnpm)?",
.{import_record.path.text},
"Could not resolve: \"{s}\"",
.{
import_record.path.text,
},
import_record.kind,
);
}
} else {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve: \"{s}\"",
.{
import_record.path.text,
},
import_record.kind,
);
}
},
// assume other errors are already in the log
@@ -2063,37 +2067,39 @@ pub const Bundler = struct {
} else |err| {
switch (err) {
error.ModuleNotFound => {
if (isPackagePath(import_record.path.text)) {
if (this.bundler.options.platform.isWebLike() and options.ExternalModules.isNodeBuiltin(import_record.path.text)) {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve Node.js builtin: \"{s}\".",
.{import_record.path.text},
import_record.kind,
);
if (!import_record.handles_import_errors) {
if (isPackagePath(import_record.path.text)) {
if (this.bundler.options.platform.isWebLike() and options.ExternalModules.isNodeBuiltin(import_record.path.text)) {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve Node.js builtin: \"{s}\".",
.{import_record.path.text},
import_record.kind,
);
} else {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve: \"{s}\". Maybe you need to \"npm install\" (or yarn/pnpm)?",
.{import_record.path.text},
import_record.kind,
);
}
} else {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve: \"{s}\". Maybe you need to \"npm install\" (or yarn/pnpm)?",
.{import_record.path.text},
"Could not resolve: \"{s}\"",
.{
import_record.path.text,
},
import_record.kind,
);
}
} else {
try log.addResolveErrorWithTextDupe(
&source,
import_record.range,
this.allocator,
"Could not resolve: \"{s}\"",
.{
import_record.path.text,
},
import_record.kind,
);
}
},
// assume other errors are already in the log

View File

@@ -329,10 +329,11 @@ pub const Linker = struct {
import_record.module_id = @truncate(u32, std.hash.Wyhash.hash(0, path.pretty));
}
} else |err| {
had_resolve_errors = true;
switch (err) {
error.ModuleNotFound => {
if (import_record.handles_import_errors) continue;
had_resolve_errors = true;
if (import_record.path.text.len > 0 and Resolver.isPackagePath(import_record.path.text)) {
if (linker.options.platform.isWebLike() and Options.ExternalModules.isNodeBuiltin(import_record.path.text)) {
try linker.log.addResolveError(
@@ -370,6 +371,8 @@ pub const Linker = struct {
}
},
else => {
had_resolve_errors = true;
try linker.log.addResolveError(
&result.source,
import_record.range,