Platforms
Troubleshooting
Fixes for missing globals, bundler resolution, WebAssembly loading, and platform capability errors.
Overview
Most platform problems come from missing globals, bundler resolution, or a package running where it is not supported. Each entry below names the error and the fix.
crypto.getRandomValues is missing
GrayClient.create throws unsupported_capability naming crypto.getRandomValues. On React Native, install react-native-get-random-values and import it on the first line of your entry file, before anything that imports @gray3/*. See the polyfills step.
TextDecoder is missing
Older Hermes builds and some bare React Native setups lack TextDecoder. Run npm install fast-text-encoding and import fast-text-encoding in polyfills.js, after react-native-get-random-values.
unsupported_capability for a chain on this platform
The family cannot do that operation on the current platform, for example Kaspa signing in a browser or Monero wallet sync on React Native. Check before calling with chainSupportsPlatform(chainId, undefined, "sign") and hide the feature. For Gram signing on React Native, call configureTon; for Polkadot enabled after start, call await ensurePolkadotCrypto(). A keystore backend that the current build cannot run, such as sqlite: { path } in a browser, throws the same code.
@gray3/cloud throws in the browser
new Gray() throws invalid_argument ("@gray3/cloud uses your project secret key and must run on a server") in browsers, extensions, and React Native. This is intentional. Move the call to your backend and call that backend from the app. See Next.js server side.
sql-wasm.wasm returns 404
The keystore web backend never loads sql.js from a CDN, and omitting both wasmUrl and locateFile throws invalid_argument. Make sure the file is served at the URL you pass: public/sql-wasm.wasm with wasmUrl: "/sql-wasm.wasm" in Next.js, the ?url import in Vite, or chrome.runtime.getURL("sql-wasm.wasm") in an extension. In extensions, a CSP error instead of a 404 means 'wasm-unsafe-eval' is missing.
Metro cannot resolve @gray3/keystore/expo or picks the wrong build
Metro is not reading package exports. Set config.resolver.unstable_enablePackageExports = true in metro.config.js on Expo SDK 51–52 or React Native 0.74–0.78, then restart Metro with --clear. Errors that mention node: modules or better-sqlite3 in a mobile bundle have the same cause.
Cannot find module better-sqlite3, sql.js, or expo-sqlite
The SQLite drivers are optional peer dependencies of @gray3/keystore. Install the one for your backend: better-sqlite3 for path, sql.js for web, and expo-sqlite for expo.
IndexedDB or window is not defined in Next.js
The keystore or client was created during server rendering. Create them in an effect or an event handler in a "use client" component, not at module scope.
No password, encryptionKey or separate masterKeyAdapter
GrayKeystore.create refuses to store an auto-generated master key next to the secrets it protects. Pass password, encryptionKey, or a separate masterKeyAdapter (for example secure storage). Use insecure: true only in development.