When using the next-payload-demo as a starting point, is it possible to store the media locally instead of in a S3 bucket?
Can I replace a S3 bucket with local media storage?
Hey @snailedlt, it would depend on where you deploy your project. The
next-payload
repo that this demo is based on is designed to be deployable on Vercel, which is serverless, and therefor doesn't have persistant file storage.
I see, that clears things up quite a bit, thanks!
If I were to test locally though, is there any reason why simply removing the cloudstorage plugin wouldn't work?
// Can I remove this code to store the images locally?
cloudStorage({
collections: {
'media': {
adapter,
disablePayloadAccessControl: true,
}
},
}),
I'm not super familiar with the repo, but I think you might run into issues with the files not saving properly. Because this repo is optimized for serverless, there might be some changes made that prevent that.
I see, thank you very much for all the help. I'm still quite new to payload so having active support from the devs like this is enormously helpful!
@tylandavis I only need the S3 bucket for the Media collection right? Looking at the code (
https://github.com/search?q=repo%3Apayloadcms%2Fnext-payload-demo%20s3&type=code) it doesn't seem like it's not used for anything else, but just want to make sure there's no magic going on in the background
I'm mainly wondering because I removed the Media collection and all of the S3 code references, but I'm still getting this error in vercel:
Error: The Serverless Function "index" is 63.48mb which exceeds the maximum size limit of 50mb. Learn More: https://vercel.link/serverless-function-size
Which leads me to believe Payload CMS might be doing some magic with other static files when the cloudStorage plugin is enabled?
Were you getting that error before removing the S3 stuff? It could be related to something else.
I didn't connect with S3 in the first place since I don't have an amazon account 😓 Do you have any ideas what it could be related to?
When I build locally everything except the cache comes out to 22.9MB or 23.1MB on disc. The cache alone is 582MB though
"index" in the error message makes me think this is likely a component somewhere causing the issue, but I don't know why one would be 63.48mb
I was saving static files in the public folder. Gonna try to remove them and see if that was the reason
That could be it. I think if you are importing files into a server component, then the file size might include those imports.
sadly that wasn't the issue :/
It's now 63.49, so .01 higher than before
It couldn't be this right?
That's the only component I've added to payload.config.ts
Seems like it might be an ongoing issue with next:
https://github.com/vercel/next.js/issues/42641Yeah it looks like
swc/core
is the common thread here
yup :/
According to a lot of comments on the github issue the fix seems to be to add this to next.config.js
outputFileTracingExcludes: {
'*': [
'./node_modules/@swc/core-linux-x64-gnu',
'./node_modules/@swc/core-linux-x64-musl',
],
},
But that's already added through the withPayloadMethod here:
Which we use like this:
// next.config.js
const { withPayload } = require("@payloadcms/next-payload");
const path = require("path");
/** @type {import('next').NextConfig} */
const nextConfig = withPayload(
{
reactStrictMode: true,
transpilePackages: ["@payloadcms/plugin-seo", "ui"],
experimental: {
serverActions: true,
},
images: {
domains: [
"localhost",
"nextjs-vercel.payloadcms.com",
process.env.NEXT_PUBLIC_APP_URL,
`${process.env.NEXT_PUBLIC_S3_ENDPOINT}`.replace("https://", ""),
],
},
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
},
{
configPath: path.resolve(__dirname, "./payload/payload.config.ts"),
}
);
module.exports = nextConfig;
Could the implementation of withPayloadMethod be wrong?
For example I noticed that the withPayloadMethod uses
"**/*": [
"node_modules/@swc/core-linux-x64-gnu",
"node_modules/@swc/core-linux-x64-musl",
...
],
instead of
'*': [
'./node_modules/@swc/core-linux-x64-gnu',
'./node_modules/@swc/core-linux-x64-musl',
],
Could the fact that I put the project in a monorepo (turborepo + pnpm-workspaces) have something to do with it perhaps?
@jmikrut It seems you were the one that added
outputFileTracingExcludes
to withPayload here:
https://github.com/payloadcms/next-payload/commit/e4d62322f03dfd87fcb84375a0eeee89fb6d9252. Do you have any idea why the excluded node_modules still show up in the logs on vercel?
ref:
https://discord.com/channels/967097582721572934/1141325269383258152/1141776387540254730Note that I'm using payload inside of a turborepo with pnpm-workspaces, and the payload app is based on the official
next-payload-demo
repo
It works with
outputFileTracingIgnores.
Seems like there's a bug currently where it doesn't work with
outputFileTracingExcludes
, but it does with
outputFileTracingIgnores
.
See
https://github.com/vercel/next.js/issues/54245for more info.
Probably would be good to change the
next-payload
code to use
outputFileTracingIgnores
until it's fixed
I wonder, should line 65 be
outputFileTracingExcludes: outputFileTracingExcludes,
?
I'm not set up at the moment to test if that works, but I think we are passing the object to
experimental
instead of
experimental.outputFileTracingExcludes
Yeah I think you're right
Unfortunately I don't have much time to contribute to the project, so I hope someone else can fix it if that's the issue 🙂
I can test the solution in the project I'm working on atm, but cba to setup next-payload locally, so it would have to be deployed somewhere
No worries, I'll see about testing that change and let you know what I find.
Thanks so much for all the time you've spent looking into this, it's been super helpful!
Thanks the same! It's been tremendously helpful for us too!
Let me know if you need me to test it once changes are implemented 🙂
If you just pass a variable into an object like that, it will key it with the var name and the contents of the var will be the value of it.
okay, I wasn't sure if that was the case or not
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.