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

Issue when using in Vercel edge functions #56

Open
lgrammel opened this issue Jun 12, 2023 · 4 comments · May be fixed by #67
Open

Issue when using in Vercel edge functions #56

lgrammel opened this issue Jun 12, 2023 · 4 comments · May be fixed by #67

Comments

@lgrammel
Copy link

I'm developing a library ( https://github.com/lgrammel/ai-utils.js ) and was using cuid2. However, it throws the following error when using it in Vercel edge functions:

- error node:crypto
Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:crypto
../../node_modules/@noble/hashes/esm/cryptoNode.js
../../node_modules/@noble/hashes/esm/utils.js
../../node_modules/@noble/hashes/esm/sha3.js
../../node_modules/@paralleldrive/cuid2/src/index.js
../../node_modules/@paralleldrive/cuid2/index.js
../../dist/vector-db/VectorDB.js
../../dist/vector-db/index.js
../../dist/index.js

It's most likely caused by the limited API availability in edge functions ( see https://nextjs.org/docs/messages/node-module-in-edge-runtime ) and could be solved by configuring webpack. However, since I'm developing a library I don't want to expose my users to this.

I've switched to nanoid v3 for the time being, which seems to work w/o issues in that environment, but I'd like to switch back to cuid2 in case this issue is fixable.

@ericelliott
Copy link
Collaborator

This is a known issue due to a dependency on noblehashes. We can open an issue there and try to get it addressed, or find an alternative, security-audited Sha-3 implementation to depend on. (Maybe one used by the Ethereum Web3 stuff?). I'm leaning this way anyway due to noble's dependency on TextEncoder APIs that are not available in some environments.

@Amar-Gill
Copy link

fwiw it works with no issue in my nuxt3 project deployed to vercel edge functions

@GenuineRex
Copy link

I tracked down an error using cuid2 to this issue on my docker image/node version. Any progress removing this dependency?

@adworacz
Copy link

adworacz commented Oct 2, 2024

Perhaps something like Oslo's crypto module might be a good option, as it seems to be in the same spirit as @noble/hashes: https://github.com/oslo-project/crypto

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

Successfully merging a pull request may close this issue.

5 participants