Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect mongodb inside rsc #34080

Closed
ghost opened this issue Feb 8, 2022 · 2 comments
Closed

Cannot connect mongodb inside rsc #34080

ghost opened this issue Feb 8, 2022 · 2 comments
Labels
bug Issue was opened via the bug report template.

Comments

@ghost
Copy link

ghost commented Feb 8, 2022

Run next info (available from version 12.0.8 and up)

Binaries:
Node: 17.4.0
npm: 8.3.1
Yarn: 3.1.1
pnpm: N/A
Relevant packages:
next: 12.0.10
react: 18.0.0-rc.0
react-dom: 18.0.0-rc.0

What version of Next.js are you using?

12.0.10

What version of Node.js are you using?

17.4.0

What browser are you using?

Brave

What operating system are you using?

Windows

How are you deploying your application?

next dev

Describe the Bug

When i try to use mongoose to connect to mongodb in server components it gives me an error:
TypeError: mongoose__WEBPACK_IMPORTED_MODULE_0___default(...).createConnection is not a function

Expected Behavior

It should not happen since it is inside server component, so it shouldn't import with webpack(web env), instead it should be import with default node env

To Reproduce

  1. create server component
  2. import mongoose inside it
  3. write code to connect mongodb with mongoose
  4. run nextjs
@ghost ghost added the bug Issue was opened via the bug report template. label Feb 8, 2022
@ghost ghost changed the title Cannot connect to mongodb with rsc Cannot connect mongodb inside rsc Feb 8, 2022
@balazsorban44
Copy link
Member

Until recently, when using RSC, you were forced to use the web runtime. #34068 makes this globally switchable, included in the canary release for now. A per-page switch is coming soon.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

1 participant