Next.js Discord

Discord Forum

middleware file too heavy

Unanswered
Spectacled Caiman posted this in #help-forum
Open in Discord
Spectacled CaimanOP
The error that stops my deployment says src/middleware is 3.08MB but your current plan allows a maximum file size of 1MB All I have is this code. I have no error in development but when I push to prduction I get this error.

Middleware’s file: https://sourceb.in/RoeRxYEDL9
getUser function: https://sourceb.in/hkg4tnP26A

15 Replies

European sprat
What happens if you just define the getUser function inside the middleware
Spectacled CaimanOP
I don’t know. I can try but is it because it’s in a separate file?
European sprat
I'm just throwing out ideas for troubleshooting to narrow things down
Maybe it's because it's in the separate file but it should be smart enough to split things out for you. Maybe it's whatever your "constants" variable is
Asian black bear
The only thing you aren't really showing is what is in ./utils/api. Although it should be code split, you are using file-scoped variables from within the getUser function which could confuse things
for example, 'constants' could be coming with a lot of other baggage
@European sprat Maybe it's because it's in the separate file but it should be smart enough to split things out for you. Maybe it's whatever your "constants" variable is
Spectacled CaimanOP
Oh this could happen it is a large file including a bunch of icons texts and states
Asian black bear
so, another easier idea might be to export the strings directly instead of wrapped in an object
like export const api_endpoint = "hello world"
@Asian black bear so, another easier idea might be to export the strings directly instead of wrapped in an object
Spectacled CaimanOP
So instead of one big object a bunch of small arrays, objects, and strings? Would that help if it’s all still in one file?
Asian black bear
yes, that would be easy for code splitting to deal with
and you could actually use a synthetic import to get a similar effect if you moved everything to separate exports.
In /utils/api
export const api_route="test"
export const key="secret"
import * as constants from './utils/api'

// These would work
constants.api_route;
constants.key;