Crypto module not working on edge
Unanswered
Cape horse mackerel posted this in #help-forum
Cape horse mackerelOP
I'm using the 'crypto' Node.js module in my middleware logic, but even thought documentation says it is supported at the edge runtime, the logs when I deploy it says the following:
Then what could I use instead or how to fix it?
A Node.js module is loaded ('crypto' at line 2) which is not supported in the Edge Runtime.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtimeThen what could I use instead or how to fix it?
6 Replies
Masai Lion
Node js modules etc are not supported in middlewares due to edge runtime. A work around that might work for you is to create an api endpoint and do your stuff there. Then in the middleware call the api end point using the desired method and play with the response from it . Hope you get my point . Also a side note to this approach I'm not sure if its recommended so feel free to correct me 🙂
@Masai Lion Node js modules etc are not supported in middlewares due to edge runtime. A work around that might work for you is to create an api endpoint and do your stuff there. Then in the middleware call the api end point using the desired method and play with the response from it . Hope you get my point . Also a side note to this approach I'm not sure if its recommended so feel free to correct me 🙂
Cape horse mackerelOP
Understood, and makes sense, but also wondering why it’s shown here. https://nextjs.org/docs/pages/api-reference/edge
Masai Lion
Am what are you trying to do with it ... If you click on the crypto link it says global read only props
@Masai Lion Am what are you trying to do with it ... If you click on the crypto link it says global read only props
Cape horse mackerelOP
I'm using it to hash passwords, but then I see I have to use SubtleCrypto instead, right?
Masai Lion
No idea tbf I haven't used crypto in a middleware before 😦
@Masai Lion No idea tbf I haven't used crypto in a middleware before 😦
Cape horse mackerelOP
It should work tho, because it says its methods are not read only, and that's what I'm using, weird that it gives a warning when deploying on vercel