arashsheyda / nuxt-mongoose

A Nuxt module for simplifying the use of Mongoose in your project.
https://docs.arashsheyda.me/nuxt-mongoose
76 stars 14 forks source link

Error: Cannot resolve "@aws-sdk/credential-providers" on edge worker functions #32

Open MickL opened 1 year ago

MickL commented 1 year ago

Thanks, this plugin looks amazing! It works fine on my local dev but deploying to Vercel Edge Functions I get the following error:

[17:58:03.988] [success] Server built in 7799ms [17:58:04.056] [success] [nitro] Generated public .vercel/output/static [17:58:04.085] [info] [nitro] Building Nitro Server (preset: vercel_edge) [17:58:16.880] [error] [nitro] Error: Cannot resolve "@aws-sdk/credential-providers" from "/vercel/path0/node_modules/mongodb/lib/deps.js" and externals are not allowed!

I dont exactly understand why would it even need @aws-sdk/credential-providers?

It works on my local dev and also when I deploy to normal Vercel (not to Edge Functions using NITRO_PRESET="vercel-edge") it works just fine.

arashsheyda commented 1 year ago

I havn't try it on edge but will do and try to find the problem, thanks for the issue 👍

nicokempe commented 11 months ago

Same for Cloudflare, after i installed @aws-sdk/credential-providers the module just required the next dependency, and the next and so on. Do you have any idea what could be the reason for this or have you perhaps already looked into it?

nicokempe commented 10 months ago

Any news on this issue? Currently this problem blocks all deployments for us, is there a way I could support you to get this work again? Have you already looked into this problem?

arashsheyda commented 10 months ago

@nicokempe I'm so sorry but I don't have experience with edge, so I wasn't successful. I'll ask others, and if you have a solution PR is more than welcome. thanks

nicokempe commented 10 months ago

Seems like the MongoDB package itself is not edge compatible. The dependencies that make problems are a sub-dependency of MongoDB and I have read on StackOverflow that this is not only known but not really possible without workarounds like a REST Relay...

Vercel itself provides guidelines on making libraries compatible with their Edge Functions runtime. This includes using a subset of Web APIs like fetch, Request, and Response, and avoiding certain Node.js APIs and JavaScript features that are not supported in the Edge Runtime. For MongoDB specifically, it seems like you should use the MongoDB Data API, which is HTTP-based​ but they say "While it is not a full replacement for the MongoDB driver, it does provide a way to access MongoDB from a browser or edge-computing service like Cloudflare Workers" themselves so I dont know how good of an alternative that is..

I have just joined the unofficial MongoDB community Discord and opened a Ticket at MongoDB and asked if anybody knows if the MongoDB package is going to be edge support because I couldnt find any information about that

References:

rainer85ah commented 7 months ago

@nicokempe Thanks Nico for the information and resources shared but let me ask you for a new update or any other workaround you have found on this issue.

[info] [nitro] Building Nuxt Nitro server (preset: cloudflare-pages) [error] [nitro] Error: Cannot resolve "@aws-sdk/credential-providers" from "/opt/buildhome/repo/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/deps.js" and externals are not allowed!

ParsaJR commented 3 months ago

image

likely the same error ( when deploy using NuxtHub ) so we can not use mongoose on cloudflare pages right?

whitersun commented 3 months ago

I have the same error with nuxthub and cloudflare with error call by not resolve something influrrent with "snappy" in mongodb. otherwise If I use cloudflare to start project and install nuxt-mongoose, I got the error call 'Cannot resolve "@aws-sdk/credential-providers'

I have spent to much time for solution of mongoose using on cloudflare. Does have any solution, I got this solution, but I still unclean does it work, look complicated have lots of step to setup.

https://www.mongodb.com/developer/products/atlas/cloudflare-worker-rest-api/

MickL commented 3 months ago

Personally I switched over to use Drizzle + PostgreSQL. On Cloudflare you can use Drizzle + Cloudflare D1 (NoSQL)

whitersun commented 3 months ago

Personally I switched over to use Drizzle + PostgreSQL. On Cloudflare you can use Drizzle + Cloudflare D1 (NoSQL)

Seem like sound good, I will try. Thank you MickL for the advise ❤

arashsheyda commented 3 months ago

@whitersun you can try the stack in https://hub.nuxt.com/

whitersun commented 3 months ago

@whitersun you can try the stack in https://hub.nuxt.com/

yeah, nuxthub is something very cool, I was using nuxt to storage my data. I just confuse when unable to using mongodb. Hope something like zeabur, able to add mongodb and auto key to management.

nicokempe commented 2 months ago

@nicokempe Thanks Nico for the information and resources shared but let me ask you for a new update or any other workaround you have found on this issue.

[info] [nitro] Building Nuxt Nitro server (preset: cloudflare-pages) [error] [nitro] Error: Cannot resolve "@aws-sdk/credential-providers" from "/opt/buildhome/repo/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/deps.js" and externals are not allowed!

I have seen this just now I am sorry 😅, I have worked a week on the migration to Supabase because I couldn't get it to run on Cloudflare Pages with MongoDB. I am pretty happy with that decision now even though I prefer NoSQL databases like MongoDB over relational databases like PostgreSQL.