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

[backport v2] createhash Support Turbopack #468

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/early-boxes-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/utils.createhash": patch
---

Compatibility with Next.js Turbopack
8 changes: 7 additions & 1 deletion packages/createHash/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { isNodeLike } from "@apollo/utils.isnodelike";

export function createHash(kind: string): import("crypto").Hash {
if (isNodeLike) {
// Some Node-like environments (like next.js Turbopack) apparently
// don't have module.require, so double-check before we call it.
// (But don't change the value of isNodeLike because other logic depends on it,
// like Apollo Server signal handling defaults.) This does mean that
// Turbopack will call sha.js instead of the native crypto module, but
// it sure beats throwing because module.require does not exist.
if (isNodeLike && module.require) {
// Use module.require instead of just require to avoid bundling whatever
// crypto polyfills a non-Node bundler might fall back to.
return module.require("crypto").createHash(kind);
Expand Down