vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.84k stars 26.65k forks source link

after adding --turbo flag and adding turbo options in config mongoose not connecting to db #68425

Open nikhilgoswami opened 1 month ago

nikhilgoswami commented 1 month ago

Link to the code that reproduces this issue

https://github.com/nikhilgoswami/mongoose-error-on-turbo.git

To Reproduce

In a project connect to db run project with yarn dev in postman run api post localhost:3000/api/example mongoose stops working if you remove --turbo mongoose starts working again

Current vs. Expected behavior

mongoose should work with turbo

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:28:31 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T8112
  Available memory (MB): 8192
  Available CPU cores: 8
Binaries:
  Node: 20.12.2
  npm: 10.5.0
  Yarn: 1.22.22
  pnpm: 9.0.6
Relevant Packages:
  next: 14.2.5 // Latest available version is detected (14.2.5).
  eslint-config-next: 14.2.5
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Developer Experience, Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

No response

AliRazaDev27 commented 1 month ago

Hello, the first thing i noticed after some experimenting is that i can make mongoose work by removing the instrumentationHook option from next.config.js and using connect() in you route handler instead. So there is something going on how instrumentation.ts is working with --turbo and instrumentationHook

samcx commented 1 month ago

@nikhilgoswami Are you seeing any errors in your terminal/console?

timneutkens commented 2 days ago

Please make sure to try next@canary first: https://github.com/nikhilgoswami/mongoose-error-on-turbo/blob/main/mongoose-turbo/package.json#L13 If you're still running into trouble let us know 🙏