Skip to content

Collections loaded server + clientside #205

Answered by jmikrut
zaunermax asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @zaunermax!

Great question. We have run into this exact issue in the past. The good news is that there is a super easy solution!

You need to manually prevent Webpack from including your server-only code.

In keeping to Payload's goal of sticking as close to JavaScript as possible, we just expose the Webpack config to you where you can utilize the variety of ways that Webpack allows you to do this.

As Hooks are only executed server-side, we've commonly used Webpack's alias feature to swap out our Hooks with empty modules. Here is an example of a config that does exactly this:

import path from 'path';
import { buildConfig } from 'payload/config';
import Customers from './collections/Cust…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@zaunermax
Comment options

@zaunermax
Comment options

@DanRibbens
Comment options

Answer selected by zaunermax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants