mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[resolver] Do not throw on require()/import errors when they're caught (and import is an await target)
This commit is contained in:
108
src/bundler.zig
108
src/bundler.zig
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user