Ask questionsCrypto warnings coming up for `import crypto from 'crypto'`

When running Node with --experimental-modules I'm getting warnings on crypto:


import crypto from 'crypto';
node --experimental-modules test.mjs
(node:12120) ExperimentalWarning: The ESM module loader is experimental.
(node:12120) [DEP0091] DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated.
(node:12120) [DEP0010] DeprecationWarning: crypto.createCredentials is deprecated. Use tls.createSecureContext instead.
(node:12120) [DEP0011] DeprecationWarning: crypto.Credentials is deprecated. Use tls.SecureContext instead.

Ideally we should hide deprecation warnings that are output during named exports population for core modules.

//cc @node/modules @devsnek


Answer questions Cellule

FYI for those who googled into this issue in the future using Typescript: if you have

import crypto, {randomBytes} from "crypto";
const randomBytesAsync = promisify(randomBytes);
const pseudoRandomBytesAsync = promisify(crypto.pseudoRandomBytes);

and see these warnings, just replace it with either

import {randomBytes, pseudoRandomBytes} from "crypto";
const randomBytesAsync = promisify(randomBytes);
const pseudoRandomBytesAsync = promisify(pseudoRandomBytes);


import crypto from "crypto";
const randomBytesAsync = promisify(crypto.randomBytes);
const pseudoRandomBytesAsync = promisify(crypto.pseudoRandomBytes);

When using a mix of default and selective import, Typescript will transpile it to * import causing your code to access deprecated fields.

Github User Rank List