nuxt-mongoose icon indicating copy to clipboard operation
nuxt-mongoose copied to clipboard

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

Open MickL opened this issue 2 years ago • 13 comments

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.

MickL avatar Nov 24 '23 17:11 MickL

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

arashsheyda avatar Nov 25 '23 18:11 arashsheyda

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 avatar Dec 22 '23 19:12 nicokempe

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?

nicokempe avatar Jan 17 '24 16:01 nicokempe

@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

arashsheyda avatar Jan 17 '24 16:01 arashsheyda

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:

  • https://stackoverflow.com/questions/75423777/is-there-anyway-to-get-mongodb-to-work-on-vercel-edge-serverless-functions
  • https://vercel.com/guides/library-sdk-compatible-with-vercel-edge-runtime-and-functions
  • https://github.com/drivly/mongo-fetch

nicokempe avatar Jan 22 '24 23:01 nicokempe

@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/[email protected]/node_modules/mongodb/lib/deps.js" and externals are not allowed!

rainer85ah avatar Apr 25 '24 03:04 rainer85ah

image

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

ParsaJR avatar Aug 18 '24 14:08 ParsaJR

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/

whitersun avatar Aug 19 '24 03:08 whitersun

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

MickL avatar Aug 19 '24 07:08 MickL

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 ❤

whitersun avatar Aug 20 '24 06:08 whitersun

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

arashsheyda avatar Aug 20 '24 14:08 arashsheyda

@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.

whitersun avatar Aug 20 '24 14:08 whitersun

@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/[email protected]/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.

nicokempe avatar Sep 23 '24 14:09 nicokempe