Repository: next.js
Issue: NextJS 13 and Mongoose drop OverwriteModelError sometimes
Labels: examples

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Home
    Binaries:
      Node: 20.2.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.12
      eslint-config-next: 13.4.12
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

CLI (create-next-app)

### Link to the code that reproduces this issue or a replay of the bug

https://github.com/pzoli/homework4nextjs

### To Reproduce

I try use NextJS 13.4.12 with mongoose 7.4.2 I get OverrideModelError sometimes when I fetch RestAPI from web browser.
When I fetch the restAPI several times in web browser I get this error.

### Describe the Bug

Please see the following post:
https://stackoverflow.com/questions/76846484/nextjs-13-and-mongoose-drop-overwritemodelerror-sometimes

### Expected Behavior

Fetch the proper data from the server.

### Which browser are you using? (if relevant)

Firefox 115.03, 116.0.1
Edge 115.0.1901.188

### How are you deploying your application? (if relevant)

I run project with "npm run dev" command. If I run with "npm run build" and "npm run start" the error is gone as I tested.

### The error message is?

error OverwriteModelError: Cannot overwrite `difficulty` model once compiled.
    at Mongoose.model (E:\work\integrity\Homeworks\homework4nextjs\node_modules\mongoose\lib\index.js:563:13)
    at eval (webpack-internal:///(rsc)/./app/models/Difficulty.ts:18:138)
    at (rsc)/./app/models/Difficulty.ts (E:\work\integrity\Homeworks\homework4nextjs\.next\server\app\api\difficulty\route.js:72:1)    at __webpack_require__ (E:\work\integrity\Homeworks\homework4nextjs\.next\server\webpack-runtime.js:33:42)
    at eval (webpack-internal:///(rsc)/./app/api/difficulty/route.ts:5:80)
    at (rsc)/./app/api/difficulty/route.ts (E:\work\integrity\Homeworks\homework4nextjs\.next\server\app\api\difficulty\route.js:52:1)
    at __webpack_require__ (E:\work\integrity\Homeworks\homework4nextjs\.next\server\webpack-runtime.js:33:42)
    at eval (webpack-internal:///(rsc)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fapi%2Fdifficulty%2Froute&page=%2Fapi%2Fdifficulty%2Froute&appPaths=&pagePath=private-next-app-dir%2Fapi%2Fdifficulty%2Froute.ts&appDir=E%3A%5Cwork%5Cintegrity%5CHomeworks%5Chomework4nextjs%5Capp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=E%3A%5Cwork%5Cintegrity%5CHomeworks%5Chomework4nextjs&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D!:15:128)
    at (rsc)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fapi%2Fdifficulty%2Froute&page=%2Fapi%2Fdifficulty%2Froute&appPaths=&pagePath=private-next-app-dir%2Fapi%2Fdifficulty%2Froute.ts&appDir=E%3A%5Cwork%5Cintegrity%5CHomeworks%5Chomework4nextjs%5Capp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=E%3A%5Cwork%5Cintegrity%5CHomeworks%5Chomework4nextjs&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D! (E:\work\integrity\Homeworks\homework4nextjs\.next\server\app\api\difficulty\route.js:42:1)
    at __webpack_require__ (E:\work\integrity\Homeworks\homework4nextjs\.next\server\webpack-runtime.js:33:42)
    at __webpack_exec__ (E:\work\integrity\Homeworks\homework4nextjs\.next\server\app\api\difficulty\route.js:652:39)
    at E:\work\integrity\Homeworks\homework4nextjs\.next\server\app\api\difficulty\route.js:653:28
    at Object.<anonymous> (E:\work\integrity\Homeworks\homework4nextjs\.next\server\app\api\difficulty\route.js:656:3)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1137:19)
    at require (node:internal/modules/helpers:121:18)
    at NodeModuleLoader.load (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\future\helpers\module-loader\node-module-loader.js:15:26)
    at RouteModuleLoader.load (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\future\helpers\module-loader\route-module-loader.js:15:51)
    at RouteHandlerManager.handle (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\future\route-handler-managers\route-handler-manager.js:20:67)
    at doRender (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\base-server.js:1009:58)
    at cacheEntry.responseCache.get.incrementalCache.incrementalCache (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\base-server.js:1218:34)
    at E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\response-cache\index.js:99:42
    at ResponseCache.get (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\response-cache\index.js:149:11)    at DevServer.renderToResponseWithComponentsImpl (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\base-server.js:1137:53)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async DevServer.renderPageComponent (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\base-server.js:1369:24)
    at async DevServer.renderToResponseImpl (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\base-server.js:1401:32)
    at async DevServer.pipeImpl (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\base-server.js:645:25)  
    at async Object.fn (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\next-server.js:1153:21)
    at async Router.execute (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\router.js:315:32)
    at async DevServer.runImpl (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\base-server.js:619:29)   
    at async DevServer.run (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\dev\next-dev-server.js:910:20)
    at async DevServer.handleRequestImpl (E:\work\integrity\Homeworks\homework4nextjs\node_modules\next\dist\server\base-server.js:546:20)