Skip to content

TypeError: equal is not a function in maskFragment.js with @wry/equality 0.5.7 #12898

@alexanderoskin

Description

@alexanderoskin

Issue Description

Current Behavior

Getting TypeError: equal is not a function error when using Apollo Client 4.0.3 with @wry/equality version 0.5.7 during SSR (Server-Side Rendering).

Error Stack Trace

TypeError: equal is not a function
    at maskFragment (file:///path/to/node_modules/@apollo/client/masking/maskFragment.js:23:9)
    at QueryManager.maskFragment (file:///path/to/node_modules/@apollo/client/core/QueryManager.js:948:13)
    at file:///path/to/node_modules/@apollo/client/react/hooks/useFragment.js:54:48
    at Object.useMemo (/path/to/node_modules/react-dom/cjs/react-dom-server.node.development.js:3903:20)
    at process.env.NODE_ENV.exports.useMemo (/path/to/node_modules/react/cjs/react.development.js:1209:34)
    at useFragment_ (file:///path/to/node_modules/@apollo/client/react/hooks/useFragment.js:33:24)
    at useFragment (file:///path/to/node_modules/@apollo/client/react/hooks/useFragment.js:17:51)

Root Cause Analysis

The issue is in /masking/maskFragment.js which uses:

import equal from "@wry/equality";

However, @wry/equality 0.5.7 has a build bug where the ESM version (lib/index.js) is missing the default export:

ESM version (lib/index.js) - BROKEN:

export function equal(a, b) { ... }
// Missing: export default equal;

CommonJS version (lib/bundle.cjs) - WORKS:

exports.equal = equal;
exports.default = equal;  // ← This exists

Workaround

Temporarily fix by changing the import in maskFragment.js:

// Change from:
import equal from "@wry/equality";

// To:
import { equal } from "@wry/equality";

Link to Reproduction

https://

Reproduction Steps

  1. Install Apollo Client 4.0.3
  2. Use useFragment hook in SSR context with ESM modules
  3. Error occurs because import equal from "@wry/equality" returns undefined in ESM

@apollo/client version

4.0.3

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