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

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

Open
MickL opened this issue Nov 24, 2023 · 13 comments

Comments

@MickL
Copy link

MickL commented Nov 24, 2023

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 MickL changed the title Error: Cannot resolve "@aws-sdk/credential-providers" Error: Cannot resolve "@aws-sdk/credential-providers" on edge worker functions Nov 24, 2023
@arashsheyda
Copy link
Owner

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

@nicokempe
Copy link

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
Copy link

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
Copy link
Owner

@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
Copy link

nicokempe commented Jan 22, 2024

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
Copy link

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

@ParsaJR
Copy link

ParsaJR commented Aug 18, 2024

image

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

@whitersun
Copy link

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
Copy link
Author

MickL commented Aug 19, 2024

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

@whitersun
Copy link

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
Copy link
Owner

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

@whitersun
Copy link

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants