Repository navigation
Crypto warnings coming up for import crypto from 'crypto' #23203
Description
Activity
//cc @nodejs/modules
The fix for this so far is to make those deprecated APIs non-enumerable. This also means they aren't available to named exports.
Reacted by Jordan Harband, Sindre Sorhus, Jeremiah Senkpiel, Jessie Gonzalez, Jimbolino, XGHeaven, Ben Brown, hardik-pb and Benjamin GruenbaumI prefer @jdalton's solution. Hiding the deprecation warnings might result in people unknowingly using deprecated APIs.
- added a commit that references this issue
on Oct 2, 2018 - added a commit that references this issue
on Nov 15, 2018 will this fix be backported to v10 or v11 ?
It can't be backported, its semver-major (breaks the API):
import crypto from 'crypto'; assert(crypto.DEFAULT_ENCODING);would start to assert after the change.FYI for those who googled into this issue in the future: if you have
import * as crypto from "crypto";
and see these warnings, just replace it with
import crypto from "crypto";
This helped in my case (node v9.11.2).
Reacted by Roman, Liron Navon, Duane Johnson, Soichiro Miki, Nils Müller, Max, Sang Dang, Thijs Koerselman, Iron Man, Tyler Church and 56 moreFYI 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);
or
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.
Reacted by Mathieu M-Gosselin, Jake Malone, Shirish Kamath, Vincent G, ramjyroo, Sven Jacobs, Folusho Oladipo, Vu Bao Nhu, Josh Randall, Nate Silva and 9 more- added a commit that references this issue
on Nov 12, 2019 - added a commit that references this issue
on Feb 4, 2020 - added a commit that references this issue
on Jun 30, 2020 - added a commit that references this issue
on Jul 27, 2026
When running Node with --experimental-modules I'm getting warnings on crypto:
test.mjs
Ideally we should hide deprecation warnings that are output during named exports population for core modules.
//cc @node/modules @devsnek