.server modules

.server modules

While not strictly necessary, .server modules are a good way to explicitly mark entire modules as server-only. The build will fail if any code in a .server file or .server directory accidentally ends up in the client module graph.

app
ā”œā”€ā”€ .server šŸ‘ˆ marks all files in this directory as server-only
ā”‚   ā”œā”€ā”€ auth.ts
ā”‚   ā””ā”€ā”€ db.ts
ā”œā”€ā”€ cms.server.ts šŸ‘ˆ marks this file as server-only
ā”œā”€ā”€ root.tsx
ā””ā”€ā”€ routes
    ā””ā”€ā”€ _index.tsx

.server modules must be within your Remix app directory.

Refer to the Route Module section in the sidebar for more information.

.server directories are only supported when using Remix Vite. The Classic Remix Compiler only supports .server files.

When using the Classic Remix Compiler, .server modules are replaced with empty modules and will not result in a compilation error. Note that this can result in runtime errors.

Docs and examples licensed under MIT