W
Wasp•5mo ago
prof_mark

Payload too large

I am getting a payload too large error, directing me to this line: const response = await api.post(operationRoute.path, superjsonArgs) How can adjust the max payload size for uploads?
26 Replies
kapa.ai
kapa.ai•5mo ago
Hi @prof_mark. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain information on how to adjust the max payload size for uploads in Wasp. I recommend checking the Wasp documentation or reaching out to the Wasp community for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @prof_mark, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
prof_mark
prof_markOP•5mo ago
I've tried following the directions here: https://wasp-lang.dev/docs/advanced/middleware-config#default-middleware-definitions I now have in my serverSetup.ts file:
import express from 'express';
import { type MiddlewareConfigFn } from 'wasp/server';

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Increase payload size limit
middlewareConfig.set('express.json', express.json({ limit: '50mb' }));
middlewareConfig.set('express.urlencoded', express.urlencoded({ limit: '50mb', extended: true }));

return middlewareConfig;
};
import express from 'express';
import { type MiddlewareConfigFn } from 'wasp/server';

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Increase payload size limit
middlewareConfig.set('express.json', express.json({ limit: '50mb' }));
middlewareConfig.set('express.urlencoded', express.urlencoded({ limit: '50mb', extended: true }));

return middlewareConfig;
};
but I now get an error:
[ Server!] [!] RollupError: src/server.ts (6:7): "default" is not exported by "../../../src/serverSetup.ts", imported by "src/server.ts".
[ Server!] https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
[ Server!] src/server.ts (6:7)
[ Server!] 4: import { config } from 'wasp/server'
[ Server!] 5:
[ Server!] 6: import setup from '../../../../src/serverSetup'
[ Server!] ^
[ Server!] [!] RollupError: src/server.ts (6:7): "default" is not exported by "../../../src/serverSetup.ts", imported by "src/server.ts".
[ Server!] https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
[ Server!] src/server.ts (6:7)
[ Server!] 4: import { config } from 'wasp/server'
[ Server!] 5:
[ Server!] 6: import setup from '../../../../src/serverSetup'
[ Server!] ^
Any ideas @kapa.ai
kapa.ai
kapa.ai•5mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The error message indicates that the setup function is not being exported from your serverSetup.ts file. The setup function is required by Wasp and is expected to be exported from your server setup file. In your serverSetup.ts file, you should have something like this:
import express from 'express';
import { type MiddlewareConfigFn, type ServerSetupFn } from 'wasp/server';

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Increase payload size limit
middlewareConfig.set('express.json', express.json({ limit: '50mb' }));
middlewareConfig.set('express.urlencoded', express.urlencoded({ limit: '50mb', extended: true }));

return middlewareConfig;
};

export const setup: ServerSetupFn = async () => {
// Your setup code here
};
import express from 'express';
import { type MiddlewareConfigFn, type ServerSetupFn } from 'wasp/server';

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Increase payload size limit
middlewareConfig.set('express.json', express.json({ limit: '50mb' }));
middlewareConfig.set('express.urlencoded', express.urlencoded({ limit: '50mb', extended: true }));

return middlewareConfig;
};

export const setup: ServerSetupFn = async () => {
// Your setup code here
};
The setup function is expected to be an async function and will be awaited before the server starts accepting any requests. It allows you to do any custom setup, e.g. setting up additional database/websockets or starting cron/scheduled jobs. You can read more about it in the Wasp documentation (https://wasp-lang.dev/docs/project/server-config#setupfn-extimport). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @prof_mark, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
prof_mark
prof_markOP•5mo ago
this didnt work. i am giving up for now and hopefully someonw has an idea
Filip
Filip•4mo ago
Hey @prof_mark You used a named export in serverSetup.ts, but imported it using a default import in wasp. You should either use a default export in both files, or a named export in both files. With the code you showed here, the import in main.wasp must look like import { serverMiddleWareFn } from '@src/serverSetup.ts (notice the curly braces). But more importantly, what are you uploading that exceeds the payload limit?
prof_mark
prof_markOP•4mo ago
Awesome thank you!
MEE6
MEE6•4mo ago
Wohooo @prof_mark, you just became a Waspeteer level 1!
prof_mark
prof_markOP•4mo ago
Was trying to send a 512x512 base 64 encoded image to open AI for their vision model. So really just needed to pass through. Ended up switching to sending the URL since I'm uploading the images to s3 anyway
Filip
Filip•4mo ago
Ok, good choice! Yeah, that's pretty big for a post request 😅
mm
mm•3mo ago
Hi @sodic @miho @martinsos I implented this according to the instructions however I'm encountering an error TypeError: middlewareConfig.set is not a function what did I miss
No description
martinsos
martinsos•3mo ago
Uff no idea, it is looking good to me @mm ! Which version of Wasp are you using? What does TS / LSP say, what are the functions availble on that object?
miho
miho•3mo ago
You'll need to share your Wasp file as well. I'd recommend using code blocks for sharing code: https://www.markdownguide.org/extended-syntax/#fenced-code-blocks
Extended Syntax | Markdown Guide
Advanced features that build on the basic Markdown syntax.
mm
mm•3mo ago
Hi @martinsos @miho do I need to provide the whole wasp file? Here are the code snippets wasp file
app OpenSaaS {
wasp: {
version: "^0.14.0"
},

title: "IntelTools",

.......

server: {
setupFn: import {serverMiddlewareFn} from "@src/serverSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup"
},
app OpenSaaS {
wasp: {
version: "^0.14.0"
},

title: "IntelTools",

.......

server: {
setupFn: import {serverMiddlewareFn} from "@src/serverSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup"
},
server setup
import express from 'express';
import { config, type MiddlewareConfigFn } from 'wasp/server';

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Increase payload size limit
middlewareConfig.set('express.json', express.json({ limit: '100mb' }));
middlewareConfig.set('express.urlencoded', express.urlencoded({ limit: '100mb', extended: true }));

return middlewareConfig;
};
import express from 'express';
import { config, type MiddlewareConfigFn } from 'wasp/server';

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Increase payload size limit
middlewareConfig.set('express.json', express.json({ limit: '100mb' }));
middlewareConfig.set('express.urlencoded', express.urlencoded({ limit: '100mb', extended: true }));

return middlewareConfig;
};
Error
[ Server ] pg-boss started!
[ Server!] TypeError: middlewareConfig.set is not a function
[ Server!] at serverMiddlewareFn (/Users/mm/code/intelhouse/inteltools/app/src/serverSetup.ts:6:20)
[ Server!] at startServer (/Users/mm/code/intelhouse/inteltools/app/.wasp/out/server/src/server.ts:25:10)
[ Server!] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[ Server ] pg-boss started!
[ Server!] TypeError: middlewareConfig.set is not a function
[ Server!] at serverMiddlewareFn (/Users/mm/code/intelhouse/inteltools/app/src/serverSetup.ts:6:20)
[ Server!] at startServer (/Users/mm/code/intelhouse/inteltools/app/.wasp/out/server/src/server.ts:25:10)
[ Server!] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
miho
miho•3mo ago
@mm I've done the same thing as you did and it worked for me. Where is the serverSetup.ts file located? Is it named like that: serverSetup.ts?
No description
mm
mm•3mo ago
Hi @miho it is located in app/src and yes named exactly like that it really says middlewareconfig.set is not a function does the node version matter? I'm using v20 did you not get a console error? saying middleware config set not a
martinsos
martinsos•3mo ago
We area lso using node 20! Hm weird that it works for Miho and not for you. Can you maybe check, in package-lock.json, what is the version of express.js that your app is using? Finally, is tehre any chance you could share the project with us? Maybe you could makea bare-bones project that has just that tricky part and then put it in public repo on github and share with us?
mm
mm•3mo ago
says here express ~4.18.1 . Yes I could try that
No description
martinsos
martinsos•3mo ago
@miho is it possible that this is somehow related with our update of express? Or that sometihng changes on the express side? But 4.18.1 should be fine, right?
miho
miho•3mo ago
express is not in the code path for this feature - it shouldn't matter. It's just some TS types that we wrote and then users use. @mm are things still not working for you?
mm
mm•2mo ago
Hi @miho not yet. haven't tried the bare-bones yet. busy with something else. will update you guys once I tried that one Hi @miho @martinsos found the problem. I just removed the setupFn since I'm not using it. What customizations can I do with setupFn btw.
server: {
// setupFn: import {serverMiddlewareFn} from "@src/serverSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup"
},
server: {
// setupFn: import {serverMiddlewareFn} from "@src/serverSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup"
},
martinsos
martinsos•2mo ago
Wait what was the problem? You were missing a declaration in Wasp?
mm
mm•2mo ago
the problem was I added setupFn: import {serverMiddlewareFn} from "@src/serverSetup", while importing the same function as the middlewareConfigFn that's why middlewareConfigFn was not detected. it's being executed from setupFn I guess
martinsos
martinsos•2mo ago
Oh, so because you used it in two places?
miho
miho•2mo ago
Found it - it's not because it was used in two places, it's because the middleware fn was set as the setup fn.
server: {
// This bit is causing the error:
setupFn: import { serverMiddlewareFn } from "@src/serverSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup"
}
server: {
// This bit is causing the error:
setupFn: import { serverMiddlewareFn } from "@src/serverSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup"
}
miho
miho•2mo ago
SetupFn is imported and then called e.g. serverMiddlewareFn() like this. But nothing is passed in and the middlewareConfig is undefined and then you get the error:
No description
martinsos
martinsos•2mo ago
Ok, nice!
Want results from more Discord servers?
Add your server