aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/resolver/resolver.zig9
-rw-r--r--test/bundler/bundler_browser.test.ts36
2 files changed, 39 insertions, 6 deletions
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index 8735981fc..e4d7686a4 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -32,6 +32,7 @@ const NodeFallbackModules = @import("../node_fallbacks.zig");
const Mutex = @import("../lock.zig").Lock;
const StringBoolMap = bun.StringHashMap(bool);
const FileDescriptorType = bun.FileDescriptor;
+const JSC = bun.JSC;
const allocators = @import("../allocators.zig");
const Msg = logger.Msg;
@@ -1262,12 +1263,6 @@ pub const Resolver = struct {
const had_node_prefix = strings.hasPrefixComptime(import_path, "node:");
const import_path_without_node_prefix = if (had_node_prefix) import_path["node:".len..] else import_path;
- if (had_node_prefix) {
- // because all node modules are already checked in ../linker.zig (JSC.HardcodedModule.Aliases.get) if module is not found here, it is not found at all
- // so we can just return not_found
- return .{ .not_found = {} };
- }
-
if (NodeFallbackModules.Map.get(import_path_without_node_prefix)) |*fallback_module| {
result.path_pair.primary = fallback_module.path;
result.module_type = .cjs;
@@ -1278,6 +1273,8 @@ pub const Resolver = struct {
// "fs"
// "fs/*"
// These are disabled!
+ } else if (had_node_prefix and !JSC.HardcodedModule.Aliases.has(import_path_without_node_prefix)) {
+ return .{ .not_found = {} };
} else if (had_node_prefix or
(strings.hasPrefixComptime(import_path_without_node_prefix, "fs") and
(import_path_without_node_prefix.len == 2 or
diff --git a/test/bundler/bundler_browser.test.ts b/test/bundler/bundler_browser.test.ts
index 9c9ccf8dd..c14e338f9 100644
--- a/test/bundler/bundler_browser.test.ts
+++ b/test/bundler/bundler_browser.test.ts
@@ -283,4 +283,40 @@ describe("bundler", () => {
);
},
});
+
+ itBundled("browser/ImportNonExistentNodeBuiltinShouldError", {
+ skipOnEsbuild: true,
+ files: {
+ "/entry.js": `
+ import net1 from "node:net1";
+ `,
+ },
+ bundleErrors: {
+ "/entry.js": [`Could not resolve: "node:net1". Maybe you need to "bun install"?`],
+ },
+ });
+ itBundled("browser/ImportNonExistentWithoutNodePrefix", {
+ skipOnEsbuild: true,
+ files: {
+ "/entry.js": `
+ import net1 from "net1";
+ `,
+ },
+ bundleErrors: {
+ "/entry.js": [`Could not resolve: "net1". Maybe you need to "bun install"?`],
+ },
+ });
+ itBundled("browser/TargetNodeNonExistentBuiltinShouldBeExternal", {
+ skipOnEsbuild: true,
+ files: {
+ "/entry.js": `
+ import net1 from "node:net1";
+ `,
+ },
+ target: "node",
+ onAfterBundle(api) {
+ const contents = api.readFile("out.js");
+ expect(contents).toContain('from "node:net1"');
+ },
+ });
});