N
Nuxt2mo ago
mpgalaxy

Use crypto server side in nuxt3 (3.8) with node 18

Hi, how can I use crypto server side in nuxt3 (3.8) with node 18 ? There is a recommendation for a server side plugin, but this isn't working:
# plugins/crypto.server.ts
export default defineNuxtPlugin(() => {
if (process.server) {
const crypto = require('crypto');
global.crypto = crypto;
}
})
# plugins/crypto.server.ts
export default defineNuxtPlugin(() => {
if (process.server) {
const crypto = require('crypto');
global.crypto = crypto;
}
})
Using this I get a 500 error Cannot assign to read only property 'crypto' of object '#<Object>' The recommendation came from https://github.com/nuxt/nuxt/discussions/19290
GitHub
crypto is not defined · nuxt nuxt · Discussion #19290
I'm trying to get an auth token in a way that's compatible with the Cloudflare Workers environment. CF workers uses the Web Crypto API. However, in development my API endpoints throw a 500 ...
5 Replies
kapa.ai
kapa.ai2mo ago
Hi @mpgalaxy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. However, you might find the Nuxt documentation on plugins helpful for understanding how to properly configure server-side plugins in Nuxt 3. Additionally, you may want to explore the Nuxt server framework documentation for more insights on server-side operations. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@975729328660832258> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
mpgalaxy
mpgalaxyOP2mo ago
@kapa.ai this was not helpful
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Hmm, I don't know enough to give you a confident answer yet. However, you might find the Nuxt documentation on plugins helpful for understanding how to properly configure server-side plugins in Nuxt 3. Additionally, you may want to explore the Nuxt server framework documentation for more insights on server-side operations. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@975729328660832258> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?