Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
guybedford opened this issue Oct 1, 2018 · 7 comments
Closed

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

guybedford opened this issue Oct 1, 2018 · 7 comments

Comments

@guybedford
Copy link
Contributor

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

@guybedford
Copy link
Contributor Author

//cc @nodejs/modules

@jdalton
Copy link
Member

jdalton commented Oct 1, 2018

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

@tniessen
Copy link
Member

tniessen commented Oct 1, 2018

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

aduh95 added a commit to aduh95/node that referenced this issue Oct 2, 2018
Since it is a deprecated API, a deprecation warning is printed when
loading crypto module from ESM. Making it non enumerable remove the
deprecation warning and make the API non-available to named imports.

Fixes: nodejs#23203
kiyomizumia pushed a commit to kiyomizumia/node that referenced this issue Nov 15, 2018
Since it is a deprecated API, a deprecation warning is printed when
loading crypto module from ESM. Making it non enumerable remove the
deprecation warning and make the API non-available to named imports.

PR-URL: nodejs#23222
Fixes: nodejs#23203
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
@Jimbolino
Copy link

will this fix be backported to v10 or v11 ?

@sam-github
Copy link
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.

@dko-slapdash
Copy link

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

@Cellule
Copy link

Cellule commented Jun 16, 2019

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.

nokome added a commit to stencila/sparkla that referenced this issue Nov 12, 2019
When using `import * from crypto` get warings like

> DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated

See nodejs/node#23203 (comment)
ssut pushed a commit to ssut/wideq-js that referenced this issue Feb 4, 2020
* Add refrigerator support

* Add method getDevice

* Add dishwasher

* Refactoring

* Add dryer

* Add washer

* Fixed import paths in devices/ac

* Fix Celsius to Fahrenheit convertion table

* Fixed swing mode so they are mapped to the right enum.

* Add the ACDevice to the client loader

* Small fix

* Update ac.ts

* Update client.ts

* All parameters to lowercase

* Add multi language support

* Fix for comments

* Add localization support

* Update README.md

* Add tslint

* Refactoring

* Some fixes for tslint

* Add devices to export

* Fix "[DEP0091] DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated." (nodejs/node#23203)

* Add more options for RefrigeratorDevice

* Small fix for washer

* Add parameter --token into cli

* Add method setOn

* Add OnOffEnum

* Update README.md

* Fix for lookupReference
Add more device types

Co-authored-by: Tom Green <tomgreen981111@yahoo.com>
ssut pushed a commit to ssut/wideq-js that referenced this issue Mar 4, 2020
* Add refrigerator support

* Add method getDevice

* Add dishwasher

* Refactoring

* Add dryer

* Add washer

* Fixed import paths in devices/ac

* Fix Celsius to Fahrenheit convertion table

* Fixed swing mode so they are mapped to the right enum.

* Add the ACDevice to the client loader

* Small fix

* Update ac.ts

* Update client.ts

* All parameters to lowercase

* Add multi language support

* Fix for comments

* Add localization support

* Update README.md

* Add tslint

* Refactoring

* Some fixes for tslint

* Add devices to export

* Fix "[DEP0091] DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated." (nodejs/node#23203)

* Add more options for RefrigeratorDevice

* Small fix for washer

* Add parameter --token into cli

* Add method setOn

* Add OnOffEnum

* Update README.md

* Fix for lookupReference
Add more device types

* Fix for lookupEnum

Co-authored-by: Tom Green <tomgreen981111@yahoo.com>
tylerlevine pushed a commit to BitGo/BitGoJS that referenced this issue Jun 30, 2020
This avoid an unwanted deprecation notice.

See nodejs/node#23203 for more details.

Ticket: BG-22502
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants