Skip to content

Collection endpoints - errors with modules #678

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

You must be logged in to vote

Hey @wojciechkrol — this is because you need to use Webpack aliases to make sure that your custom endpoint code is not loaded into the admin JS bundle. Because the entire Payload config is imported directly in Webpack, and you now have your custom endpoint handlers imported in your Payload code, the admin panel is actually trying to load and execute those modules. And, fs is a server-side only package built into Node.

Here's an example from one of our projects, where we alias a bunch of server-only modules:

    webpack: (config) => ({
      ...config,
      resolve: {
        ...config.resolve,
        alias: [
          path.resolve(__dirname, './hookHelperFunctions/stripeFunctions'),

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by wojciechkrol
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants