Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Server only modules are being accessed in client buncle when using Cloud Storage plugin for S3 #23

Closed
jgb-solutions opened this issue Apr 26, 2023 · 3 comments

Comments

@jgb-solutions
Copy link

jgb-solutions commented Apr 26, 2023

I'm trying to use the cloud storage plugin. Unfortunately I can't because when I try to use the admin panel I get this:
Module not found: Can't resolve 'fs'

Screenshot 2023-04-25 at 8 30 03 PM

It's trying to load the cloudStorage plugin's dependencies. Especially 'fs'. I read https://payloadcms.com/docs/admin/webpack for webpack. But I'm using Next.js, the integration should be flawless I guess. How to fix this?

Also I'm using Zod to parse the .env variables for some config values for the plugin and also for generating types. Since the config is ran on both the server and the client Zod is erroring out because it can't read the env vars. I had to import dotenv to make the generation of types' script work, but can't do anything when it's trying to load the code in the admin panel.

@jmikrut
Copy link
Member

jmikrut commented Apr 28, 2023

Hey @jgb-solutions — you might have an issue related to the following issue which is open on the actual cloud storage plugin:

payloadcms/plugin-cloud-storage#49

Can you check that and make sure that you are properly initializing the cloud storage plugin?

TL;DR: the plugin is responsible itself for adjusting your Webpack config, but if you don't actually initialize it at all, it won't adjust your Webpack config at all. You need to make sure that it is indeed executing otherwise you will see dependency issues like what you've reported.

This is indeed functional though. Take a look at how the next-payload-demo repo uses it:
https://github.com/payloadcms/next-payload-demo/blob/main/payload/payload.config.ts

I will close this but I am happy to help further - so just let me know if you can't get it to work. Might need to have you share your Payload config for further help though. 👍

@jmikrut jmikrut closed this as completed Apr 28, 2023
@jgb-solutions
Copy link
Author

@jmikrut thanks, it worked when I put everything together.

@revnelson
Copy link

I'm using this plugin and it seems to be working, but when I query a media item the url is /media/image_file_name.png and there is no route handler for that so the image won't load. How can I get this to work?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants