Skip to content

Cannot connect mongodb inside rsc #34080

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions