Skip to content

Error: crypto.getRandomValues() not supported on node.js #3950

Answered by au-z
maxbritto asked this question in Q&A
Discussion options

You must be logged in to vote

@maxbritto - thanks for your succinct explanation. I was running into the same situation using vite and was able to work around this issue with a combination of rollup settings and a small polyfill borrowing some basic logic from the react-native-get-random-values polyfill.

Changes to vite.config.ts:

import { nodeResolve } from '@rollup/plugin-node-resolve'

export default defineConfig({
  build: {
    // ...
    rollupOptions: {
      output: {
        globals: {crypto: 'crypto'},
      },
      external: ['crypto'],
      plugins: [nodeResolve({ preferBuiltins: true })],
    },
  },
})

My understanding is that these settings will direct the build/bundle to use the nodejs crypto module i…

Replies: 10 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@ACronje
Comment options

@maxbritto
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by RanVaknin
Comment options

You must be logged in to vote
1 reply
@adussarps
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@rajeshbejugam
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet