aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bundler/bundle_v2.zig44
-rw-r--r--src/logger.zig25
-rw-r--r--src/options.zig2
3 files changed, 63 insertions, 8 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig
index 67cdee041..64aaf54d9 100644
--- a/src/bundler/bundle_v2.zig
+++ b/src/bundler/bundle_v2.zig
@@ -511,8 +511,8 @@ pub const BundleV2 = struct {
source,
import_record.range,
this.graph.allocator,
- "Could not resolve Node.js builtin: \"{s}\". To use Node.js builtins, set target to 'node' or 'bun'",
- .{path_to_use},
+ "Browser build cannot {s} Node.js module: \"{s}\". To use Node.js builtins, set target to 'node' or 'bun'",
+ .{ import_record.kind.label(), path_to_use },
import_record.kind,
) catch unreachable;
} else {
@@ -1914,8 +1914,8 @@ pub const BundleV2 = struct {
source,
import_record.range,
this.graph.allocator,
- "Could not resolve Node.js builtin: \"{s}\". To use Node.js builtins, set target to 'node' or 'bun'",
- .{import_record.path.text},
+ "Browser build cannot {s} Node.js builtin: \"{s}\". To use Node.js builtins, set target to 'node' or 'bun'",
+ .{ import_record.kind.label(), import_record.path.text },
import_record.kind,
) catch @panic("unexpected log error");
} else {
@@ -9799,15 +9799,45 @@ const LinkerContext = struct {
// time, so we emit a debug message and rewrite the value to the literal
// "undefined" instead of emitting an error.
symbol.import_item_status = .missing;
- c.log.addRangeWarningFmt(
+ if (c.resolver.opts.target == .browser and JSC.HardcodedModule.Aliases.has(next_source.path.pretty, .bun)) {
+ c.log.addRangeWarningFmtWithNote(
+ source,
+ r,
+ c.allocator,
+ "Browser polyfill for module \"{s}\" doesn't have a matching export named \"{s}\"",
+ .{
+ next_source.path.pretty,
+ named_import.alias.?,
+ },
+ "Bun's bundler defaults to browser builds instead of node or bun builds. If you want to use node or bun builds, you can set the target to \"node\" or \"bun\" in the bundler options.",
+ .{},
+ r,
+ ) catch unreachable;
+ } else {
+ c.log.addRangeWarningFmt(
+ source,
+ r,
+ c.allocator,
+ "Import \"{s}\" will always be undefined because there is no matching export in \"{s}\"",
+ .{
+ named_import.alias.?,
+ next_source.path.pretty,
+ },
+ ) catch unreachable;
+ }
+ } else if (c.resolver.opts.target == .browser and JSC.HardcodedModule.Aliases.has(next_source.path.pretty, .browser)) {
+ c.log.addRangeErrorFmtWithNote(
source,
r,
c.allocator,
- "Import \"{s}\" will always be undefined because there is no matching export in \"{s}\"",
+ "Browser polyfill for module \"{s}\" doesn't have a matching export named \"{s}\"",
.{
- named_import.alias.?,
next_source.path.pretty,
+ named_import.alias.?,
},
+ "Bun's bundler defaults to browser builds instead of node or bun builds. If you want to use node or bun builds, you can set the target to \"node\" or \"bun\" in the bundler options.",
+ .{},
+ r,
) catch unreachable;
} else {
c.log.addRangeErrorFmt(
diff --git a/src/logger.zig b/src/logger.zig
index d1b89438b..f47637684 100644
--- a/src/logger.zig
+++ b/src/logger.zig
@@ -1108,6 +1108,31 @@ pub const Log = struct {
});
}
+ pub fn addRangeErrorFmtWithNote(
+ log: *Log,
+ source: ?*const Source,
+ r: Range,
+ allocator: std.mem.Allocator,
+ comptime fmt: string,
+ args: anytype,
+ comptime note_fmt: string,
+ note_args: anytype,
+ note_range: Range,
+ ) !void {
+ @setCold(true);
+ if (!Kind.shouldPrint(.err, log.level)) return;
+ log.errors += 1;
+
+ var notes = try allocator.alloc(Data, 1);
+ notes[0] = rangeData(source, note_range, allocPrint(allocator, note_fmt, note_args) catch unreachable);
+
+ try log.addMsg(.{
+ .kind = .err,
+ .data = rangeData(source, r, allocPrint(allocator, fmt, args) catch unreachable),
+ .notes = notes,
+ });
+ }
+
pub fn addWarning(log: *Log, source: ?*const Source, l: Loc, text: string) !void {
@setCold(true);
if (!Kind.shouldPrint(.warn, log.level)) return;
diff --git a/src/options.zig b/src/options.zig
index 57b39aeaa..aaeb1fce8 100644
--- a/src/options.zig
+++ b/src/options.zig
@@ -87,7 +87,7 @@ pub const ExternalModules = struct {
};
pub fn isNodeBuiltin(str: string) bool {
- return NodeBuiltinsMap.has(str);
+ return bun.JSC.HardcodedModule.Aliases.has(str, .node);
}
const default_wildcard_patterns = &[_]WildcardPattern{