Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

middleware size extremely large on build #599

Closed
t2pellet opened this issue Nov 4, 2023 · 4 comments
Closed

middleware size extremely large on build #599

t2pellet opened this issue Nov 4, 2023 · 4 comments
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@t2pellet
Copy link

t2pellet commented Nov 4, 2023

Description

Hi, I was trying to deploy my Next.js site on Vercel, and its failing due to the middleware.ts file being too big:

Error: The Edge Function "src/middleware" size is 2.47 MB and your plan size limit is 1 MB. Learn More: https://vercel.link/edge-function-size

image

I tried looking around a bit and couldn't seem to grasp why the middleware would need to be that large.

My middleware is purely just the next-intl middleware, nothing else:

import createMiddleware from 'next-intl/middleware';
import { languages } from '@/types';

export default createMiddleware({
  locales: languages,
  defaultLocale: 'en',
});

export const config = {
  matcher: ['/((?!api|_next|_vercel|.*\\..*).*)'],
};

I'm using:

    "next": "13.5.4",
    "next-intl": "^3.0.0-rc.7",
    "react": "^18.2.0",
    "react-dom": "^18",

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://github.com/t2pellet/tenzin.live

Reproduction description

Steps to reproduce:

  1. Use next-intl middleware in middleware.ts
  2. Try to deploy to Vercel

Expected behaviour

The middleware.ts file should be a smaller/more reasonable size

@t2pellet t2pellet added bug Something isn't working unconfirmed Needs triage. labels Nov 4, 2023
@t2pellet t2pellet changed the title middleware size too large on build middleware size extremely large on build Nov 4, 2023
@t2pellet
Copy link
Author

t2pellet commented Nov 4, 2023

I've dug around a bit more and it appears to be a Nextjs issue after all -- its bundling things it shouldn't be with the middleware for some reason.

Closing!

@t2pellet t2pellet closed this as completed Nov 4, 2023
@amannn
Copy link
Owner

amannn commented Nov 5, 2023

Thanks for investigating! Can you link to the issue on the Next.js side?

@apavlinovic
Copy link

@amannn @t2pellet I think this needs to be reopened. It is not nextjs, it is the fact that we are including messages on every request in the i18n configuration of Next Intl.

Basically, when you write

export default getRequestConfig(async ({ locale }) => {
return {}
}

Where you import JSON files, those JSON files are bundled by webpack, since you explicitly ask us to import them. This is causing the bloat in middleware size – this is not a NextJS problem, it's a next-intl problem!

@amannn
Copy link
Owner

amannn commented Jan 25, 2024

Let's continue the discussion in #814

Repository owner locked as resolved and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

3 participants