#Middleware - Dynamic Code Evaluation error

14 messages · Page 1 of 1 (latest)

young wyvern
#

I'm getting an error when trying to run very basic middleware in my Next 12.1.0 app.

I have a file called /pages/_middleware.tsx with the following very basic code:

import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
export default (req: NextRequest, response: NextResponse) => {
  console.log('running basic middleware')
}

It all works fine locally, but when I push to Vercel I'm getting this build error:
Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Middleware pages/_middleware

I don't understand, because there's obviously no dynamic code evaluation happening. Could it be that middleware in 12.1.0 is broken on Vercel because it was a beta feature?

Thanks!

young wyvern
#

The error definitely mentions something about babel:

Failed to compile.
../../node_modules/@babel/runtime/helpers/construct.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Middleware pages/_middleware
Import trace for requested module:
../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js
#

@burnt quiver although I'll have to check my package setup to confirm if it is...

#

It looks like a few things I'm depending on use babel

#

Oh is it not working because babel is a node-based system?

#

If so, is there any guidance on how to decouple it from babel?

burnt quiver
young wyvern
burnt quiver
young wyvern
burnt quiver
young wyvern
#

@burnt quiver I don't know exactly where to do that... is it possible to set it up to just have SWC replace babel for certain folders?