Repository: next.js
Issue: using mongoose in edge runtime, Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
Labels: bug,Runtime

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.13.0
      npm: 8.19.3
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.4.3
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

### Link to the code that reproduces this issue or a replay of the bug

https://github.com/Aralhi/aiworks/blob/main/pages/api/chatgpt/get2.ts

### To Reproduce

when i use mongoose in nextjs edge runtime meet this error

./node_modules/_mongoose@7.2.0@mongoose/dist/browser.umd.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/_mongoose@7.2.0@mongoose/dist/browser.umd.js
./lib/dbConnect.ts
./lib/completion.ts

does mongoose support nextjs edge runtime?

api/get.ts
```
const handler = async (req: Request, res: Response) => {
   await dbConnect
})

```
 dbconnect.ts
```
import mongoose from 'mongoose'

const MONGODB_URI = process.env.MONGODB_URI || ''

if (!MONGODB_URI) {
  throw new Error(
    'Please define the MONGODB_URI environment variable inside .env.local'
  )
}

let cached = global.mongoose

if (!cached) {
  cached = global.mongoose = { conn: null, promise: null }
}

async function dbConnect() {
  if (cached.conn) {
    return cached.conn
  }

  if (!cached.promise) {
    const opts = {
      bufferCommands: false,
    }

    cached.promise = mongoose.connect(MONGODB_URI, opts).then((mongoose) => {
      return mongoose
    })
  }

  try {
    cached.conn = await cached.promise
  } catch (e) {
    cached.promise = null
    throw e
  }

  return cached.conn
}

export default dbConnect
```

### Describe the Bug

when i using mongoose in edge runtime and meet this issue. it is easy to reproduce just like the code above.

./node_modules/_mongoose@7.2.0@mongoose/dist/browser.umd.js

> dist/browser.umd.js is Mongoose's browser build, so unless you're using Mongoose on the frontend that code is unused

why the edge api will build mongoose browser build.

and i try to use unstable_allowDynamic to ignore it, but it doesn't work.
```
export const config = {
  runtime: "edge",
  unstable_allowDynamic: [
    '/node_modules/mongoose/dist/browser.umd.jsz'
  ]
};
```

### Expected Behavior

maybe don't build **/node_modules/mongoose/dist/browser.umd.js** and i call my edge api without error.

### Which browser are you using? (if relevant)

Chrome 113.0.5672.126

### How are you deploying your application? (if relevant)

next dev,next build,vercel