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 and cannot be bundled with worker presets #949

Closed
manniL opened this issue Feb 16, 2023 · 15 comments
Closed

mongodb and cannot be bundled with worker presets #949

manniL opened this issue Feb 16, 2023 · 15 comments
Labels
discussion documentation Improvements or additions to documentation enhancement New feature or request

Comments

@manniL
Copy link
Contributor

manniL commented Feb 16, 2023

Environment

  • Operating System: Darwin
  • Node Version: v18.13.0
  • Nitro Version: edge-2.2.2-27941588.be1ac07
  • Package Manager: pnpm@7.27.0

Reproduction

https://github.com/manniL/rm-nitro-externals-mongodb

  1. Clone Repo
  2. pnpm i
  3. pnpm build
  4. See error

Describe the bug

When building, the following error occurs:

Error: Cannot resolve "@mongodb-js/zstd" from "/path/to/project/node_modules/.pnpm/mongodb@5.0.1/node_modules/mongodb/lib/deps.js" and externals are not allowed!

Additional context

Similar to #947

Logs

No response

@manniL manniL added pending triage bug Something isn't working and removed pending triage labels Feb 16, 2023
@pi0 pi0 added the enhancement New feature or request label Feb 16, 2023
@pi0
Copy link
Member

pi0 commented Feb 16, 2023

Thanks for making the reproduction.

I have a fix for the particular first issue we encounter. However, the mongodb library is not the most popular to be bundler friendly to be fully packed by rollup. It has many implicit often optional dependencies in tree such as aws-sdk, aws4 and native ones and snappy. And mongo is not alone... Even vue needed weeks in Nuxt side to be bundle friendly.

We might finally require a preset of configurations or special packed distro of MongoDB.

Are you trying to deploy it on a worker target?

@pi0 pi0 changed the title MongoDB and noExternals: true leads to build error mongodb and cannot be bundled with worker presets Feb 16, 2023
@manniL
Copy link
Contributor Author

manniL commented Feb 16, 2023

Thanks for making the reproduction.
It has many implicit often optional dependencies in tree such as aws-sdk, aws4 and native ones and snappy.

Yes indeed, but I think they are optional, at least according to deps.ts here.

We might finally require a preset of configurations or special packed distro of MongoDB.

Sounds reasonable indeed.

Are you trying to deploy it on a worker target?

Yup, CF workers 🙈

@dargmuesli
Copy link
Contributor

Just out of curiosity:

Even vue needed weeks in Nuxt side to be bundle friendly.

What was needed to make Vue bundle friendly?

@pi0
Copy link
Member

pi0 commented Feb 16, 2023

@manniL
Copy link
Contributor Author

manniL commented Feb 16, 2023

After further research I wonder if mongodb on CF workers would even work w/o nitro (and without e.g. using the MongoDB Atlas Data API) 🙈

Because of TCP/IP you might need Cloudflare tunnel like for mysql.

Further read: https://developers.cloudflare.com/workers/learning/integrations/databases/

Maybe also worth checking e.g. https://github.com/denodrivers/mongo

@TylorMayfield
Copy link

I'm having the same issue on "vercel-edge"

@itpropro
Copy link
Contributor

@manniL I don't think mongodb will work, as of the missing raw support for TCP/UDP that you mentioned. Even the official Mongo documentation only references the Realm SDK for Workers.
For node.js target, the mongodb package works and is bundled fine in my tests.
Maybe for now we could add a section about "libraries that don't work with certain targets" or something similar to the docs?

@pi0
Copy link
Member

pi0 commented Feb 16, 2023

For node.js target, the mongodb package works and is bundled fine in my tests.

It works with externals tracer indeed (still lots of duplicate deps as you know 🙈). It would probably worth to make it better anyway at least for Node.js target. (if possible)

Maybe for now we could add a section about "libraries that don't work with certain targets" or something similar to the docs?

Sound like a nice idea for docs! Maybe in Deployment>Overview>Workers and mention workers limits + possible current worker targets? (deno, cloudflare, vercel edge, netlify edge -- they all share similar limits and specs)

@pi0 pi0 added documentation Improvements or additions to documentation discussion and removed bug Something isn't working labels Feb 16, 2023
@flozero
Copy link

flozero commented Feb 19, 2023

I hit the same problem here. Does it mean we can't use mongo db with their server less approach ?

What is the recommandation here please :s

@manniL
Copy link
Contributor Author

manniL commented Feb 19, 2023

I hit the same problem here. Does it mean we can't use mongo db with their server less approach ?

What is the recommandation here please :s

Serverless is fine ✅
Non-node environment like CF workers is not ❌
* For that, you'd use realm.js / realm-web instead
* My "real-life" example

@flozero
Copy link

flozero commented Feb 20, 2023

I changed for supabase personnally

@itpropro
Copy link
Contributor

I added your example to #953 @manniL

@eladcandroid
Copy link

@TylorMayfield Did you manage to solve it with vercel-edge preset?

@yabuking84
Copy link

yabuking84 commented Dec 11, 2023

Having the same issue, setting NITRO_PRESET to remove edge workers (ex. setting it to just vercel instead of vercel-edge) creates the bundle but I would really like to use the edge workers. Any workarounds? I see using Realm SDK was suggested.

@pi0
Copy link
Member

pi0 commented May 16, 2024

Some engines such as pg recently support edge-workers using native connect() and seems mongo is not yet so even if we fix any possible bundling issues it won't be working.

For mongoDB and incompatible databases, you often need an HTTP gateway. Check this example with cloudflare+atlas/realm: https://www.mongodb.com/developer/products/atlas/cloudflare-worker-rest-api/

@pi0 pi0 closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants