镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Crypto warnings coming up for import crypto from 'crypto' #23203

Description

@guybedford

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

test.mjs

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

Activity

  1. guybedford commented on Oct 1, 2018

    @guybedford
    ContributorAuthor

    //cc @nodejs/modules

  2. jdalton commented on Oct 1, 2018

    @jdalton
    Member

    The fix for this so far is to make those deprecated APIs non-enumerable. This also means they aren't available to named exports.

  3. tniessen commented on Oct 1, 2018

    @tniessen
    Member

    I prefer @jdalton's solution. Hiding the deprecation warnings might result in people unknowingly using deprecated APIs.

  4. Jimbolino commented on Dec 5, 2018

    @Jimbolino

    will this fix be backported to v10 or v11 ?

  5. sam-github commented on Dec 5, 2018

    @sam-github
    Contributor

    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.

  6. dko-slapdash commented on May 13, 2019

    @dko-slapdash

    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).

  7. Cellule commented on Jun 16, 2019

    @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);

    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.

  8. added a commit that references this issue on Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions