Next-intl middleware occurs Next-auth Dynamic evaluation error

I have Next.JS 14.2.3 project which contains next-auth.js and next-intl with versions:

Whose versions are latest as for now (next-intl 3.17.2 latest).

Problem

While building the project from time to time I’m facing following error:

Failed to compile.

./node_modules@babelruntimeregeneratorindex.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

Import trace for requested module:
  ./node_modules@babelruntimeregeneratorindex.js
  ./node_modulesnext-authreactindex.js
  ./srccomponentsinterfaceheaderindex.tsx
  ./srccomponentsinterfaceindex.ts
  ./srccomponentsindex.ts
  ./srcconstbuilder-by-type.ts
  ./srcconstindex.ts
  ./srcmiddleware.ts


> Build failed because of webpack errors

for a random next-auth function e.g. signIn, useSession or signOut.

This time error points to the header.tsx file:

'use client';

import { signIn, useSession } from 'next-auth/react';
import { useTranslations } from 'next-intl';
import { useCallback, useMemo, useState } from 'react';

import { Dropdown, IconedButton, RelativeBox, SignOutModal } from '@/components';
import { GlobeIcon, SignInIcon, SignOutIcon, WFLogo } from '@/icons';
import { flags } from '@/icons/flags';
import { AvatarVector } from '@/icons/vectors';

import s from './header.module.scss';

export const Header = () => {
   const t = useTranslations();
   const { data: session } = useSession();

   const [langDropdownOpened, setLangDropdownOpened] = useState<boolean>(false);
   const [accountDropdownOpened, setAccountDropdownOpened] = useState<boolean>(false);
   const [signOutOpened, setSignOutOpened] = useState<boolean>(false);

   const handleSignIn = () => {
      signIn('keycloak');
   };

   const dropdownOptions = useMemo<TDropdownOption[]>(
      () => [
         {
            icon: flags.Ukraine,
            label: t('Languages.ua'),
            variant: 'original',
            onClick: () => {}, // TODO add language change
         },
         {
            icon: flags.Germany,
            label: t('Languages.de'),
            variant: 'original',
            onClick: () => {}, // TODO add language change
         },
         {
            icon: flags.USA,
            label: t('Languages.en'),
            variant: 'original',
            onClick: () => {}, // TODO add language change
         },
      ],
      [],
   );

   const toggleLangDropdown = useCallback(() => setLangDropdownOpened(prev => !prev), []);
   const toggleAccountDropdown = useCallback(
      () => setAccountDropdownOpened(prev => !prev),
      [],
   );
   const toggleSignOut = useCallback(() => setSignOutOpened(prev => !prev), []);

   const signInOption: TDropdownOption = useMemo<TDropdownOption>(
      () => ({
         icon: SignInIcon,
         label: t('Components.Interface.Header.signIn'),
         onClick: handleSignIn,
         variant: 'wf-primary',
      }),
      [],
   );

   const signOutOption: TDropdownOption = useMemo<TDropdownOption>(
      () => ({
         icon: SignOutIcon,
         label: t('Components.Interface.Header.signOut'),
         onClick: toggleSignOut,
         variant: 'destructive',
      }),
      [],
   );

   const targetDropdownOption = useMemo<TDropdownOption>(
      () => (session ? signOutOption : signInOption),
      [session],
   );

   return (
      <>
         <header className={s.header}>
            <WFLogo className={s.logo} />

            <section className={s.settings}>
               <RelativeBox>
                  <IconedButton
                     onClick={toggleLangDropdown}
                     size="xl"
                     variant="transparent"
                     icon={GlobeIcon}
                     tooltipPosition="bottom"
                     tooltipText={t('Tooltips.changeLang')}
                  />

                  {langDropdownOpened && (
                     <Dropdown options={dropdownOptions} onClose={toggleLangDropdown} />
                  )}
               </RelativeBox>

               <RelativeBox>
                  <IconedButton
                     icon={AvatarVector}
                     variant="transparent"
                     size="xl"
                     onClick={toggleAccountDropdown}
                  />

                  {accountDropdownOpened && (
                     <Dropdown
                        options={[targetDropdownOption]}
                        onClose={toggleAccountDropdown}
                     />
                  )}
               </RelativeBox>
            </section>
         </header>

         {signOutOpened && (
            <SignOutModal isOpened={signOutOpened} onClose={toggleSignOut} />
         )}
      </>
   );
};

Here are only useSession and signIn present and here is middleware file:

middleware.ts:

import createMiddleware from 'next-intl/middleware';
import { locales } from '@/const';

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

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

I could’ve using next-intl without routing but it’s neccessary as I have more than 5 languages in the project

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật