Skip to content

fix: favor globalThis.crypto over require('crypto') #3040

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

Closed

Conversation

styfle
Copy link

@styfle styfle commented Aug 3, 2023

In runtimes outside of Node.js, require() is not defined.

So we should favor globalThis.crypto and only fallback to require('crypto') for older versions of Node.js

https://nodejs.org/api/globals.html#crypto_1

This is following up on the work from PR #3033.

In runtimes outside of Node.js, `require()` is not defined.

So we should favor `globalThis.crypto` and only fallback to `require('crypto')` for older versions of Node.js

https://nodejs.org/api/globals.html#crypto_1
@charmander
Copy link
Collaborator

Considering that pg uses require everywhere else (with the recent Cloudflare Workers changes expecting stubs), does this help concretely?

@styfle
Copy link
Author

styfle commented Aug 3, 2023

Ah yes, I should have clarified that bundlers can handle local require('./path/to/file.js') because they are combining all the source files into one. But they typically leave require('crypto'), require('fs'), etc since those are not source files but built in modules for Node.js runtime.

@charmander
Copy link
Collaborator

charmander commented Aug 3, 2023

events, fs, and net, I mean. Which environment/use does this affect?

@styfle
Copy link
Author

styfle commented Aug 4, 2023

Good point. I'll close this then 👍

@styfle styfle closed this Aug 4, 2023
@styfle styfle deleted the fix-globalthis-crypto-precedence branch August 4, 2023 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants