#Error while building: "randomBytes" is not exported by "__vite-browser-external

1 messages · Page 1 of 1 (latest)

open barn
#

Hello there. I am new to React Router 7 world. I am trying to port my nextjs app to react router 7 app.

I am getting error while trying to use some node:crypto stuff.

During developement:

client:174 Error: Module "node:crypto" has been externalized for browser compatibility. Cannot access "node:crypto.createCipheriv" in client code.  See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
    at Object.get (__vite-browser-external:node:crypto:3:11)
    at aes.ts:1:63

During build: (pasted photo)

Why is browser trying to run this code when this is intended to run on server side only. Mere importing is giving these error.
I am using turbo repo and these are from the shared utils packages that is using node:crypto for aes.

open barn
#

Interesting error.

So I just created a new project without turbo repo and imported the aes function.

Case 1: Imported but not used
In this case I am getting error both in development and production build fails

Case 2: Imported and used
No error. Works completely fine

Now in my turbo repo case I am not using aes function but it is being exported as index.ts is handling all the exports

open barn
#

Bump

cunning lake
#

did you solve it for yourself ?