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

mongodb_connection_string_url_1.default is not a constructor #1024

Closed
lautiamkok opened this issue Mar 6, 2023 · 7 comments
Closed

mongodb_connection_string_url_1.default is not a constructor #1024

lautiamkok opened this issue Mar 6, 2023 · 7 comments
Labels

Comments

@lautiamkok
Copy link

lautiamkok commented Mar 6, 2023

Environment

Node.js: v19
nitropack: v2.2.3
mongodb: v5.1.0

Reproduction

// routes/index.ts

import { MongoClient } from 'mongodb'

export default eventHandler(async event => {
  const mongoClient = await new MongoClient('mongodb://localhost:27017').connect()
  const collection = mongoClient.db('testdb').collection('testcollection')
  const docs = await collection.find().toArray()
  client.close()
  return docs
})

Describe the bug

Get the following error on my terminal:

[nitro] [request error] [unhandled] mongodb_connection_string_url_1.default is not a constructor
  at parseOptions (/.../.nitro/dev/index.mjs:13395:19)  
  at new MongoClient (/.../.nitro/dev/index.mjs:19349:64)  
  at /.../.nitro/dev/index.mjs:20962:29  
  at /.../.nitro/dev/index.mjs:927:47  
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)  
  at async Object.handler (/.../.nitro/dev/index.mjs:983:19)  
  at async Server.toNodeHandle (/.../.nitro/dev/index.mjs:1037:7)
handling cors
✔ Nitro built in 2194 ms 

Additional context

No issue with the exact same code on the app that uses h3 directly though.

Logs

No response

@manniL
Copy link
Contributor

manniL commented Mar 6, 2023

Might be related: #949

@pi0
Copy link
Member

pi0 commented Mar 6, 2023

Can you please share a reproduction? 🙏🏼 (also what is your deployment target)

@lautiamkok
Copy link
Author

lautiamkok commented Mar 7, 2023

@pi0

Here you go:

https://github.com/lautiamkok/Nitro-MongoDB

Would like to deploy it to a Node.js server as an API on a custom port like 5000.

@Dav3rs
Copy link

Dav3rs commented Mar 26, 2023

I'm having the same issue, and I just moved the same exact code to a nuxt api route and it woks! Currently using nuxt as a backend microservice because of this 😅, without pages, just consuming the api routes.

Copy link
Contributor

@lautiamkok I can't access your reproduction. Please provide a new one either with github or stackblitz. This might a duplicate as @manniL suggested.

@Hebilicious Hebilicious added bug Something isn't working database needs reproduction and removed pending triage labels Jun 30, 2023 — with Volta.net
@CooLNuanfeng

This comment was marked as duplicate.

@pi0
Copy link
Member

pi0 commented May 17, 2024

Closing due to lack of reproduction. It is likely that you face this issue when trying to bundle mongo for edge-targets. Please consider that mongodb package is not compatible with edge.

@pi0 pi0 closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants