Next-auth middleware is throwing error on deploy

Hello,

I have a standard nextjs website with nrwl.
I added a middleware.ts file with next-auth redirect :

export { default } from 'next-auth/middleware';
export const config = { matcher: ['/app/(.*)'] };

But on netlify build, I have an error when it’s deploying

 Packaging Edge Functions from .netlify/edge-functions directory:
7:59:16 AM:  - next_src_middleware
7:59:18 AM: Function 'next_src_middleware' uses an unsupported regular expression and will not be invoked:
7:59:18 AM: /^(?:\\/(_next\\/data\\/[^\/]{1,}))?(?:\\/([^\/.]{1,}))?\\/app(?:\\/(.*))(.json)?[\\/#\?]?$/
7:59:18 AM:        ^
7:59:18 AM: Unexpected token: "/" at 1:7.

Full deploy log is

8:55:13 AM: Waiting for other deploys from your team to complete. Check the queue: https://app.netlify.com/teams/linkyflow/builds
8:58:41 AM: Build ready to start
8:58:43 AM: build-image version: 7fd17ad8d79d1952d384fb389d8e787becff0260 (focal)
8:58:43 AM: buildbot version: 7fd17ad8d79d1952d384fb389d8e787becff0260
8:58:43 AM: Fetching cached dependencies
8:58:43 AM: Starting to download cache of 2.4GB
8:58:58 AM: Finished downloading cache in 15.103s
8:58:58 AM: Starting to extract cache
8:59:17 AM: Finished extracting cache in 19.085s
8:59:17 AM: Finished fetching cache in 34.36s
8:59:17 AM: Starting to prepare the repo for build
8:59:17 AM: Preparing Git Reference refs/heads/prod
8:59:18 AM: Parsing package.json dependencies
8:59:19 AM: Different build command detected, going to use the one specified in the Netlify configuration file: 'yarn run build:prod' versus 'npm run build:prod' in the Netlify UI
8:59:20 AM: Starting build script
8:59:20 AM: Installing dependencies
8:59:20 AM: Python version set to 2.7
8:59:20 AM: Started restoring cached Node.js version
8:59:27 AM: Finished restoring cached Node.js version
8:59:27 AM: v16.19.1 is already installed.
8:59:27 AM: Now using node v16.19.1 (npm v8.19.3)
8:59:27 AM: Enabling Node.js Corepack
8:59:27 AM: Started restoring cached build plugins
8:59:27 AM: Finished restoring cached build plugins
8:59:28 AM: Attempting Ruby version 2.7.2, read from environment
8:59:28 AM: Using Ruby version 2.7.2
8:59:28 AM: Using PHP version 8.0
8:59:28 AM: WARNING: The environment variable 'NODE_ENV' is set to 'production'. Any 'devDependencies' in package.json will not be installed
8:59:28 AM: Started restoring cached corepack dependencies
8:59:28 AM: Finished restoring cached corepack dependencies
8:59:28 AM: Started restoring cached yarn cache
9:00:29 AM: Finished restoring cached yarn cache
9:00:29 AM: No yarn workspaces detected
9:00:29 AM: Started restoring cached node modules
9:00:29 AM: Finished restoring cached node modules
9:00:30 AM: Installing npm packages using Yarn version 1.22.19
9:00:30 AM: yarn install v1.22.19
9:00:30 AM: [1/4] Resolving packages...
9:00:31 AM: success Already up-to-date.
9:00:31 AM: Done in 0.82s.
9:00:31 AM: npm packages installed using Yarn
9:00:31 AM: Started restoring cached go cache
9:00:31 AM: Finished restoring cached go cache
9:00:31 AM: go version go1.19.7 linux/amd64
9:00:31 AM: Detected 1 framework(s)
9:00:31 AM: "next-nx" at version "15.4.4"
9:00:31 AM: Section completed: initializing
9:00:33 AM: ​
9:00:33 AM:   Netlify Build                                                 
9:00:33 AM: ────────────────────────────────────────────────────────────────
9:00:33 AM: ​
9:00:33 AM: ❯ Version
9:00:33 AM:   @netlify/build 29.6.4
9:00:33 AM: ​
9:00:33 AM: ❯ Flags
9:00:33 AM:   baseRelDir: true
9:00:33 AM:   buildId: 640d8561158ac50008ad67ef
9:00:33 AM:   deployId: 640d8561158ac50008ad67f1
9:00:33 AM: ​
9:00:33 AM: ❯ Current directory
9:00:33 AM:   /opt/build/repo
9:00:33 AM: ​
9:00:33 AM: ❯ Config file
9:00:33 AM:   /opt/build/repo/netlify.toml
9:00:33 AM: ​
9:00:33 AM: ❯ Context
9:00:33 AM:   production
9:00:33 AM: ​
9:00:33 AM: ❯ Using Next.js Runtime - v4.31.0
9:00:34 AM: ​
9:00:34 AM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
9:00:34 AM: ────────────────────────────────────────────────────────────────
9:00:34 AM: ​
9:00:35 AM: Next.js cache restored.
9:00:35 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
9:00:35 AM: ​
9:00:35 AM: (@netlify/plugin-nextjs onPreBuild completed in 452ms)
9:00:35 AM: ​
9:00:35 AM:   2. build.command from netlify.toml                            
9:00:35 AM: ────────────────────────────────────────────────────────────────
9:00:35 AM: ​
9:00:35 AM: $ yarn run build:prod
9:00:35 AM: yarn run v1.22.19
9:00:35 AM: $ env-cmd -f ./apps/front/.env.production nx run front:build:production && env-cmd -f ./apps/front/.env.production  nx run front:sitemap 
9:00:36 AM: > nx run front:build:production
9:00:36 AM: Debugger listening on ws://0.0.0.0:9229/6cfa7e8f-3630-4836-875d-8807460d1c75
9:00:36 AM: For help, see: https://nodejs.org/en/docs/inspector
9:00:38 AM: info  - Loaded env from apps/front/.env.production
9:00:38 AM: info  - Loaded env from apps/front/.env
9:00:39 AM: info  - Skipping linting
9:00:39 AM: info  - Checking validity of types...
9:00:44 AM: info  - Creating an optimized production build...
9:00:49 AM: info  - Compiled successfully
9:00:49 AM: info  - Collecting page data...
9:00:59 AM: info  - Generating static pages (38/38)
9:00:59 AM: info  - Finalizing page optimization...
9:00:59 AM: Route (pages)                                                                                                Size     First Load JS
9:00:59 AM: β”Œ ● /                                                                                                        6.85 kB         189 kB
9:00:59 AM: β”œ   /_app                                                                                                    0 B             140 kB
9:00:59 AM: β”œ β—‹ /404                                                                                                     4.4 kB          185 kB
9:00:59 AM: β”œ Ξ» /api/auth/[...nextauth]                                                                                  0 B             140 kB
9:00:59 AM: β”œ ● /app/budget                                                                                              1.59 kB         239 kB
9:00:59 AM: β”œ ● /app/categories                                                                                          14.9 kB         252 kB
9:00:59 AM: β”œ ● /app/dashboard                                                                                           190 kB          387 kB
9:00:59 AM: β”œ ● /app/export                                                                                              24.7 kB         217 kB
9:00:59 AM: β”œ ● /app/import                                                                                              19.6 kB         219 kB
9:00:59 AM: β”œ ● /app/mapping                                                                                             571 B           191 kB
9:00:59 AM: β”œ ● /app/transaction                                                                                         3.17 kB         234 kB
9:00:59 AM: β”œ ● /auth/error                                                                                              4.4 kB          185 kB
9:00:59 AM: β”œ Ξ» /auth/signin                                                                                             10.3 kB         200 kB
9:00:59 AM: β”œ ● /auth/signout                                                                                            3.88 kB         186 kB
9:00:59 AM: β”œ ● /auth/verify-request                                                                                     3.83 kB         184 kB
9:00:59 AM: β”œ ● /blog                                                                                                    5.18 kB         186 kB
9:00:59 AM: β”” ● /success                                                                                                 4.37 kB         185 kB
9:00:59 AM: + First Load JS shared by all                                                                                144 kB
9:00:59 AM:   β”œ chunks/framework-c7996656ed34e4e7.js                                                                     67 kB
9:00:59 AM:   β”œ chunks/main-b5508de4b78066ca.js                                                                          28 kB
9:00:59 AM:   β”œ chunks/pages/_app-9f7eb6f7d5ee862c.js                                                                    43.5 kB
9:00:59 AM:   β”œ chunks/webpack-924c5efa05b8a19e.js                                                                       1.84 kB
9:00:59 AM:   β”” css/e2e217f71a47f4ec.css                                                                                 3.87 kB
9:00:59 AM: Ζ’ Middleware                                                                                                 62.3 kB
9:00:59 AM: Ξ»  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
9:00:59 AM: β—‹  (Static)  automatically rendered as static HTML (uses no initial props)
9:00:59 AM: ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
9:01:00 AM:  >  NX   Successfully ran target build for project front
9:01:01 AM: > nx run front:sitemap
9:01:01 AM: Debugger listening on ws://0.0.0.0:9229/78a1ab08-5fa4-47d4-ae55-42d6a631c920
9:01:01 AM: For help, see: https://nodejs.org/en/docs/inspector
9:01:01 AM: Starting inspector on 0.0.0.0:9229 failed: address already in use
9:01:01 AM: ✨ [next-sitemap] Loading next-sitemap config: file:///opt/build/repo/apps/front/next-sitemap.config.js
9:01:01 AM: βœ… [next-sitemap] Generation completed
9:01:01 AM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
9:01:01 AM: β”‚    (index)    β”‚ Values β”‚
9:01:01 AM: β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
9:01:01 AM: β”‚ indexSitemaps β”‚   1    β”‚
9:01:01 AM: β”‚   sitemaps    β”‚   1    β”‚
9:01:01 AM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
9:01:01 AM: -----------------------------------------------------
9:01:01 AM:  SITEMAP INDICES
9:01:01 AM: -----------------------------------------------------
9:01:01 AM:    β—‹ https://linkyflow.com/sitemap.xml
9:01:01 AM: -----------------------------------------------------
9:01:01 AM:  SITEMAPS
9:01:01 AM: -----------------------------------------------------
9:01:01 AM:    β—‹ https://linkyflow.com/sitemap-0.xml
9:01:01 AM:  >  NX   Successfully ran target sitemap for project front
9:01:01 AM: $ env-cmd -f ./apps/front/.env.production next-sitemap --config apps/front/next-sitemap.config.js
9:01:01 AM: ✨ [next-sitemap] Loading next-sitemap config: file:///opt/build/repo/apps/front/next-sitemap.config.js
9:01:01 AM: βœ… [next-sitemap] Generation completed
9:01:01 AM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
9:01:01 AM: β”‚    (index)    β”‚ Values β”‚
9:01:01 AM: β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
9:01:01 AM: β”‚ indexSitemaps β”‚   1    β”‚
9:01:01 AM: β”‚   sitemaps    β”‚   1    β”‚
9:01:01 AM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
9:01:01 AM: -----------------------------------------------------
9:01:01 AM:  SITEMAP INDICES
9:01:01 AM: -----------------------------------------------------
9:01:01 AM:    β—‹ https://linkyflow.com/sitemap.xml
9:01:01 AM: -----------------------------------------------------
9:01:01 AM:  SITEMAPS
9:01:01 AM: -----------------------------------------------------
9:01:01 AM:    β—‹ https://linkyflow.com/sitemap-0.xml
9:01:01 AM: Done in 26.32s.
9:01:01 AM: ​
9:01:01 AM: (build.command completed in 26.4s)
9:01:01 AM: ​
9:01:01 AM:   3. @netlify/plugin-nextjs (onBuild event)                     
9:01:01 AM: ────────────────────────────────────────────────────────────────
9:01:01 AM: ​
9:01:01 AM: NextAuth package detected, NEXTAUTH_URL environment variable set by user in Netlify configuration to https://linkyflow.com
9:01:01 AM: Patching /opt/build/repo/node_modules/next/dist/server/base-server.js
9:01:01 AM: Done
9:01:01 AM: Patching /opt/build/repo/node_modules/next/dist/server/next-server.js
9:01:01 AM: Done
9:01:01 AM: Moving static page files to serve from CDN...
9:01:01 AM: Moved 66 files
9:01:01 AM: You are not using Netlify Edge Functions for image format detection. Set env var "NEXT_FORCE_EDGE_IMAGES=true" to enable.
9:01:01 AM: ✨ Deploying middleware and functions to Netlify Edge Functions ✨
9:01:01 AM: This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge
9:01:01 AM: Netlify configuration property "redirects" value changed to [
9:01:01 AM:   { from: '/_next/static/*', to: '/static/:splat', status: 200 },
9:01:01 AM:   {
9:01:01 AM:     from: '/:locale/_next/static/*',
9:01:01 AM:     to: '/static/:splat',
9:01:01 AM:     status: 200
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/image*',
9:01:01 AM:     query: { url: ':url', w: ':width', q: ':quality' },
9:01:01 AM:     to: '/_ipx/w_:width,q_:quality/:url',
9:01:01 AM:     status: 301
9:01:01 AM:   },
9:01:01 AM:   { from: '/_ipx/*', to: '/.netlify/builders/_ipx', status: 200 },
9:01:01 AM:   { from: '/cache/*', to: '/404.html', status: 404, force: true },
9:01:01 AM:   { from: '/server/*', to: '/404.html', status: 404, force: true },
9:01:01 AM:   { from: '/serverless/*', to: '/404.html', status: 404, force: true },
9:01:01 AM:   { from: '/trace', to: '/404.html', status: 404, force: true },
9:01:01 AM:   { from: '/traces', to: '/404.html', status: 404, force: true },
9:01:01 AM:   { from: '/BUILD_ID', to: '/404.html', status: 404, force: true },
9:01:01 AM:   {
9:01:01 AM:     from: '/',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: true,
9:01:01 AM:     conditions: { Cookie: [Array] }
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/*',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     conditions: { Cookie: [Array] },
9:01:01 AM:     force: true
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/index.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/index.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/app/budget.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/app/budget',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/app/budget.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/app/budget',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/app/categories.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/app/categories',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/app/categories.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/app/categories',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/app/dashboard.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/app/dashboard',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/app/dashboard.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/app/dashboard',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/app/export.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/app/export',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/app/export.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/app/export',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/app/import.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/app/import',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/app/import.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/app/import',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/app/mapping.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/app/mapping',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/app/mapping.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/app/mapping',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/app/transaction.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/app/transaction',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/app/transaction.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/app/transaction',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/auth/error.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/auth/error',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/auth/error.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/auth/error',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/auth/signin.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/auth/signin',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/auth/signin.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/auth/signin',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/auth/signout.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/auth/signout',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/auth/signout.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/auth/signout',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/auth/verify-request.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/auth/verify-request',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/auth/verify-request.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/auth/verify-request',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/blog.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/blog',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/blog.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/blog',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/success.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/success',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/success.json',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/success',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/blog/:slug.json',
9:01:01 AM:     to: '/server/pages/en/404.html',
9:01:01 AM:     status: 404,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/blog/:slug',
9:01:01 AM:     to: '/server/pages/en/404.html',
9:01:01 AM:     status: 404,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/blog/:slug.json',
9:01:01 AM:     to: '/server/pages/fr/404.html',
9:01:01 AM:     status: 404,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/blog/:slug',
9:01:01 AM:     to: '/server/pages/fr/404.html',
9:01:01 AM:     status: 404,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/en/legal/:slug.json',
9:01:01 AM:     to: '/server/pages/en/404.html',
9:01:01 AM:     status: 404,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/legal/:slug',
9:01:01 AM:     to: '/server/pages/en/404.html',
9:01:01 AM:     status: 404,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/_next/data/rUpAyrjQ7qG4RNBo_jZJd/fr/legal/:slug.json',
9:01:01 AM:     to: '/server/pages/fr/404.html',
9:01:01 AM:     status: 404,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/fr/legal/:slug',
9:01:01 AM:     to: '/server/pages/fr/404.html',
9:01:01 AM:     status: 404,
9:01:01 AM:     force: false
9:01:01 AM:   },
9:01:01 AM:   {
9:01:01 AM:     from: '/*',
9:01:01 AM:     to: '/.netlify/functions/___netlify-handler',
9:01:01 AM:     status: 200
9:01:01 AM:   }
9:01:01 AM: ].
9:01:01 AM: ​
9:01:01 AM: (@netlify/plugin-nextjs onBuild completed in 297ms)
9:01:01 AM: ​
9:01:01 AM:   4. Functions bundling                                         
9:01:01 AM: ────────────────────────────────────────────────────────────────
9:01:01 AM: ​
9:01:01 AM: Packaging Functions from .netlify/functions-internal directory:
9:01:01 AM:  - ___netlify-handler/___netlify-handler.js
9:01:01 AM:  - ___netlify-odb-handler/___netlify-odb-handler.js
9:01:01 AM:  - _ipx/_ipx.js
9:01:01 AM: ​
9:01:41 AM: ​
9:01:41 AM: (Functions bundling completed in 40s)
9:01:41 AM: ​
9:01:41 AM:   5. Edge Functions bundling                                    
9:01:41 AM: ────────────────────────────────────────────────────────────────
9:01:41 AM: ​
9:01:41 AM: Packaging Edge Functions from .netlify/edge-functions directory:
9:01:41 AM:  - next_src_middleware
9:01:43 AM: Function 'next_src_middleware' uses an unsupported regular expression and will not be invoked:
9:01:43 AM: /^(?:\\/(_next\\/data\\/[^\/]{1,}))?(?:\\/([^\/.]{1,}))?\\/app(?:\\/(.*))(.json)?[\\/#\?]?$/
9:01:43 AM:        ^
9:01:43 AM: Unexpected token: "/" at 1:7.
9:01:43 AM: ​
9:01:43 AM: (Edge Functions bundling completed in 1.2s)
9:01:43 AM: ​
9:01:43 AM:   6. @netlify/plugin-nextjs (onPostBuild event)                 
9:01:43 AM: ────────────────────────────────────────────────────────────────
9:01:43 AM: ​
9:01:43 AM: Next.js cache saved.
9:01:43 AM: ​
9:01:43 AM: (@netlify/plugin-nextjs onPostBuild completed in 223ms)
9:01:43 AM: ​
9:01:43 AM:   7. Deploy site                                                
9:01:43 AM: ────────────────────────────────────────────────────────────────
9:01:43 AM: ​
9:01:43 AM: Starting to deploy site from 'dist/apps/front/.next'
9:01:43 AM: Calculating files to upload
9:01:44 AM: 71 new files to upload
9:01:44 AM: 2 new functions to upload
9:01:53 AM: Section completed: deploying
9:01:53 AM: Site deploy was successfully initiated
9:01:53 AM: ​
9:01:53 AM: (Deploy site completed in 10.5s)
9:01:54 AM: ​
9:01:54 AM: Starting post processing
9:01:54 AM:   Netlify Build Complete                                        
9:01:54 AM: ────────────────────────────────────────────────────────────────
9:01:54 AM: ​
9:01:54 AM: (Netlify Build completed in 1m 21s)
9:01:54 AM: Post processing - HTML
9:01:54 AM: Caching artifacts
9:01:54 AM: Started saving node modules
9:01:54 AM: Finished saving node modules
9:01:54 AM: Started saving build plugins
9:01:54 AM: Finished saving build plugins
9:01:54 AM: Started saving corepack cache
9:01:54 AM: Finished saving corepack cache
9:01:54 AM: Started saving yarn cache
9:01:55 AM: Post processing - header rules
9:01:56 AM: Post processing - redirect rules
9:01:56 AM: Post processing done
9:01:56 AM: Section completed: postprocessing
9:01:57 AM: Site is live ✨
9:03:05 AM: Finished saving yarn cache
9:03:05 AM: Started saving pip cache
9:03:05 AM: Finished saving pip cache
9:03:05 AM: Started saving emacs cask dependencies
9:03:05 AM: Finished saving emacs cask dependencies
9:03:05 AM: Started saving maven dependencies
9:03:05 AM: Finished saving maven dependencies
9:03:05 AM: Started saving boot dependencies
9:03:05 AM: Finished saving boot dependencies
9:03:05 AM: Started saving rust rustup cache
9:03:05 AM: Finished saving rust rustup cache
9:03:05 AM: Started saving go dependencies
9:03:05 AM: Finished saving go dependencies
9:03:05 AM: Build script success
9:03:05 AM: Section completed: building
9:05:43 AM: Uploading Cache of size 2.4GB
9:05:57 AM: Section completed: cleanup
9:05:57 AM: Finished processing build request in 7m14.092s

It seems really really standard, do you know what is wrong ?

Thanks a lot !

Hi there, glad you found us :wave:t6: : before we can help you, we need a little more information on the issues you are facing.

First, have you looked through this resource? It is a compilation of all of our build and deploy resources. This is a good starting point.

If you have worked through those guides and are still encountering issues please share the following information:

  • the name of your build instance: β€œexample-jones.netlify.com”
  • what you have already tried
  • any error messages you have received in your terminal window or in the developer console

Hello SamO,

Thank you for the link.
I tried setting NODE_ENV=development for debug but I have the same issue.

Name of build instance :

What I tried :

  • The build is working fine in my laptop
  • Build is working fine if I remove the file β€œmiddleware.ts” which is located in β€œsrc”, next to my β€œpages”
  • Tried setting node_env to development with no success.

The error happen during the build/deploy edge function :

8:12:26 AM:   5. Edge Functions bundling                                    
8:12:26 AM: ────────────────────────────────────────────────────────────────
8:12:26 AM: ​
8:12:26 AM: Packaging Edge Functions from .netlify/edge-functions directory:
8:12:26 AM:  - next_src_middleware
8:12:27 AM: Function 'next_src_middleware' uses an unsupported regular expression and will not be invoked:
8:12:27 AM: /^(?:\\/(_next\\/data\\/[^\/]{1,}))?(?:\\/([^\/.]{1,}))?\\/app(?:\\/(.*))(.json)?[\\/#\?]?$/
8:12:27 AM:        ^
8:12:27 AM: Unexpected token: "/" at 1:7.
8:12:27 AM: ​
8:12:27 AM: (Edge Functions bundling completed in 1.3s)

And my middleware.ts is the most basic next-auth middleware you can get (Next.js | NextAuth.js
) :

export { default } from 'next-auth/middleware';
export const config = { matcher: ['/app/(.*)'] };

Thanks for you help,
Fabien

I’m also getting a similar error during build. Running the same regex as in the official docs from NextJS: Advanced Features: Middleware | Next.js.

/((?!api|_next/static|_next/image|favicon.ico).*)

I am experiencing the same issue using the middleware described here Next.js | NextAuth.js with Netlify

Hey folks :wave: ,

Thanks for reporting the issue. We’ve filed an investigation with our dev team and we’ll follow up here as soon as we know more!

1 Like

Hi @alianza,

This is a known issue and already being worked on.

1 Like

Hi!

I am using middleware for authentication as well and get an issue with the regex in

export const config = { matcher:  '/((?!_next/image|_next/static|favicon.ico).*)'};

The effect seems to be that _next/image is impacted and I can’t see any static images.

Is there a work-around for the issue?

One possible workaround is to modify the regular expression to specifically exclude only the routes that you want to protect with the authentication middleware, rather than trying to exclude all routes except for a few exceptions

Thanks, great! Can we track the issue somewhere?

Could we see the site in question?

We would update this thread - the original issue is internal-only

1 Like