From f93fc92312bc6078fcf58ee58eba3222f7c320a6 Mon Sep 17 00:00:00 2001 From: YanAnghelp Date: Fri, 26 Jun 2026 13:04:48 +0800 Subject: [PATCH 1/2] feat: support `server-only` and `client-only` modules (#2162) --- packages/start/env.d.ts | 12 ++++++++++++ packages/start/src/config/index.ts | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/packages/start/env.d.ts b/packages/start/env.d.ts index 2c9155d1c..c638b96cd 100644 --- a/packages/start/env.d.ts +++ b/packages/start/env.d.ts @@ -7,3 +7,15 @@ declare namespace App { [key: string | symbol]: any; } } + +/** + * Import `server-only` to ensure this module is never bundled for the client. + * Importing it in a client module will throw a build error. + */ +declare module "server-only" {} + +/** + * Import `client-only` to ensure this module is never bundled for the server. + * Importing it in a server module will throw a build error. + */ +declare module "client-only" {} diff --git a/packages/start/src/config/index.ts b/packages/start/src/config/index.ts index 9cdc6830e..77b828901 100644 --- a/packages/start/src/config/index.ts +++ b/packages/start/src/config/index.ts @@ -200,6 +200,29 @@ export function solidStart(options?: SolidStartOptions): Array { }, filter: options?.serverFunctions?.filter, }), + { + name: "solid-start:boundary-modules", + enforce: "pre", + resolveId(id, importer, { ssr }) { + if (id === "server-only") { + if (!ssr) + this.error( + `Attempt to import 'server-only' in a client module: ${importer}`, + ); + } else if (id === "client-only") { + if (ssr) + this.error( + `Attempt to import 'client-only' in a server module: ${importer}`, + ); + } else { + return null; + } + return "\0solid-start:boundary-modules:id"; + }, + load(id) { + if (id === "\0solid-start:boundary-modules:id") return "export {}"; + }, + }, { name: "solid-start:virtual-modules", async resolveId(id) { From 54fc19b3e681461d5ee98a5ea63e016ae16058f6 Mon Sep 17 00:00:00 2001 From: YanAnghelp Date: Fri, 26 Jun 2026 16:58:58 +0800 Subject: [PATCH 2/2] chore: add changeset --- .changeset/support-server-client-only.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/support-server-client-only.md diff --git a/.changeset/support-server-client-only.md b/.changeset/support-server-client-only.md new file mode 100644 index 000000000..935fe31ee --- /dev/null +++ b/.changeset/support-server-client-only.md @@ -0,0 +1,5 @@ +--- +"@solidjs/start": minor +--- + +Add support for `server-only` and `client-only` modules