dotnet/runtime · critical · Error
Using node without crypto support. To enable current operati
Error message
Using node without crypto support. To enable current operation, either provide polyfill for 'globalThis.crypto.getRandomValues' or enable 'node:crypto' module.
What it means
initPolyfillsEarly() in Node detects that globalThis.crypto.getRandomValues is missing and that dynamic import('node:crypto') failed. It then installs a getRandomValues stub that throws this exact message when called. So the error fires later, at the first crypto use, not at polyfill install time. Node 18+ has webcrypto built-in; older or stripped Node builds may not.
Source
Thrown at src/native/libs/Common/JavaScript/loader/polyfills.ts:53
}
}
if (ENVIRONMENT_IS_NODE) {
if (!globalThis.crypto) {
globalThis.crypto = <any>{};
}
if (!globalThis.crypto.getRandomValues) {
let nodeCrypto: any = undefined;
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore:
nodeCrypto = await import(/*! webpackIgnore: true */"node:crypto");
} catch (err: any) {
// Noop, error throwing polyfill provided bellow
}
if (!nodeCrypto) {
globalThis.crypto.getRandomValues = () => {
throw new Error("Using node without crypto support. To enable current operation, either provide polyfill for 'globalThis.crypto.getRandomValues' or enable 'node:crypto' module.");
};
} else if (nodeCrypto.webcrypto) {
globalThis.crypto = nodeCrypto.webcrypto;
} else if (nodeCrypto.randomBytes) {
const getRandomValues = (buffer: Uint8Array) => {
if (buffer) {
buffer.set(nodeCrypto.randomBytes(buffer.length));
}
};
globalThis.crypto.getRandomValues = getRandomValues as any;
}
}
if (!globalThis.performance) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore:
globalThis.performance = (await import(/*! webpackIgnore: true */"perf_hooks")).performance;
}
}View on GitHub (pinned to 290d5ab72c)
Solutions
- Ensure node:crypto is resolvable: configure bundlers with { externals: ['node:crypto'] } or target:'node'.
- Upgrade to Node 18+ where globalThis.crypto.webcrypto is available natively.
- Provide a polyfill before bootstrapping: globalThis.crypto.getRandomValues = require('crypto').randomFillSync, or use the 'crypto' package's webcrypto.
- If you cannot enable node:crypto, install a custom getRandomValues backed by any secure RNG available in your host.
Example fix
// before
const dotnet = await dotnet.create(); // throws inside runtime when crypto used
// after — polyfill before create
const { webcrypto } = require('node:crypto');
globalThis.crypto = webcrypto;
const dotnet = await dotnet.create(); Defensive patterns
Strategy: fallback
Validate before calling
if (typeof globalThis.crypto?.getRandomValues !== 'function') {
try { await import('node:crypto'); }
catch { throw new Error('node:crypto unavailable — polyfill globalThis.crypto.getRandomValues before boot'); }
} Type guard
function hasSecureRandom(g: any): g is { crypto: { getRandomValues: (b: Uint8Array) => Uint8Array } } {
return typeof g?.crypto?.getRandomValues === 'function';
} Prevention
- Run on Node 18+ where webcrypto is global.
- Mark node:crypto external in bundler configs.
- Assert globalThis.crypto.getRandomValues in a bootstrap self-test.
When it happens
Trigger: Running under Node.js where node:crypto is unavailable (custom Node build with crypto disabled, a bundler that stubbed out node:crypto, a sandboxed runtime), and the .NET runtime then invokes crypto.getRandomValues for GUID/random generation.
Common situations: Bundling the loader with webpack/rollup without marking node:crypto as external; running in a restricted sandbox (e.g. some serverless runtimes); very old Node (<15) without webcrypto; an environment that deleted globalThis.crypto before startup.
Related errors
- No fetch implementation available
- Please install `node-fetch` and `node-abort-controller` npm
- NodeJS at '${process.execPath}' has too low version '${proce
- NotImplementedException
- No fetch implementation available
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/3780686cde33acb2.
Report an issue: GitHub.