diff --git a/.changeset/giant-otters-protect.md b/.changeset/giant-otters-protect.md new file mode 100644 index 00000000000..1a232073d3c --- /dev/null +++ b/.changeset/giant-otters-protect.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +vite: errors for server-only code point to new docs diff --git a/integration/vite-dot-server-test.ts b/integration/vite-dot-server-test.ts index 4785b8fcfd8..251e3b119db 100644 --- a/integration/vite-dot-server-test.ts +++ b/integration/vite-dot-server-test.ts @@ -144,12 +144,12 @@ test.describe("Vite / route / server-only module referenced by client", () => { ` '${specifier}' imported by route 'app/routes/_index.tsx'`, - " The only route exports that can reference server-only modules are:", + " Remix automatically removes server-code from these exports:", " `loader`, `action`, `headers`", ` But other route exports in 'app/routes/_index.tsx' depend on '${specifier}'.`, - " For more see https://remix.run/docs/en/main/discussion/server-vs-client", + " See https://remix.run/docs/en/main/future/vite#splitting-up-client-and-server-code", ].forEach(expect(stderr).toMatch); }); } @@ -209,20 +209,7 @@ test.describe("Vite / non-route / server-only module referenced by client", () = ` '${specifier}' imported by 'app/reexport-server-only.ts'`, - " * If all code in 'app/reexport-server-only.ts' is server-only:", - - " Rename it to 'app/reexport-server-only.server.ts'", - - " * Otherwise:", - - ` - Keep client-safe code in 'app/reexport-server-only.ts'`, - ` - And move server-only code to a \`.server\` file`, - ` e.g. 'app/reexport-server-only.server.ts'`, - - " If you have lots of `.server` files, try using", - " a `.server` directory e.g. 'app/.server'", - - "For more, see https://remix.run/docs/en/main/future/vite#server-code-not-tree-shaken-in-development", + " See https://remix.run/docs/en/main/future/vite#splitting-up-client-and-server-code", ].forEach(expect(stderr).toMatch); }); } diff --git a/packages/remix-dev/vite/plugin.ts b/packages/remix-dev/vite/plugin.ts index 85a5a90bfdd..1ad100b2fe9 100644 --- a/packages/remix-dev/vite/plugin.ts +++ b/packages/remix-dev/vite/plugin.ts @@ -1093,46 +1093,24 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => { "", ` '${id}' imported by route '${importerShort}'`, "", - ` The only route exports that can reference server-only modules are:`, + ` Remix automatically removes server-code from these exports:`, ` ${serverOnlyExports}`, "", ` But other route exports in '${importerShort}' depend on '${id}'.`, "", - " For more see https://remix.run/docs/en/main/discussion/server-vs-client", + " See https://remix.run/docs/en/main/future/vite#splitting-up-client-and-server-code", "", ].join("\n") ); } - let importedBy = path.parse(importerShort); - let dotServerFile = vite.normalizePath( - path.join( - importedBy.dir, - importedBy.name + ".server" + importedBy.ext - ) - ); - throw Error( [ colors.red(`Server-only module referenced by client`), "", ` '${id}' imported by '${importerShort}'`, "", - - ` * If all code in '${importerShort}' is server-only:`, - "", - ` Rename it to '${dotServerFile}'`, - "", - ` * Otherwise:`, - "", - ` - Keep client-safe code in '${importerShort}'`, - ` - And move server-only code to a \`.server\` file`, - ` e.g. '${dotServerFile}'`, - "", - " If you have lots of `.server` files, try using", - " a `.server` directory e.g. 'app/.server'", - "", - " For more, see https://remix.run/docs/en/main/future/vite#server-code-not-tree-shaken-in-development", + " See https://remix.run/docs/en/main/future/vite#splitting-up-client-and-server-code", "", ].join("\n") );