Apollo-link: Cannot read property 'delete' of undefined

Created on 14 Mar 2019  ·  24Comments  ·  Source: apollographql/apollo-link

After upgrade to [email protected] got errors.

Uncaught TypeError: Cannot read property 'delete' of undefined
    at bundle.esm.js:67
    at cleanupSubscription (Observable.js:108)
    at notifySubscription (Observable.js:169)
    at onNotify (Observable.js:196)
    at SubscriptionObserver.complete (Observable.js:258)
    at bundle.esm.js:46
    at Set.forEach (<anonymous>)
    at Object.next (bundle.esm.js:45)
    at notifySubscription (Observable.js:152)
    at onNotify (Observable.js:196)
    at SubscriptionObserver.next (Observable.js:248)
    at Object.next (bundle.esm.js:32)
    at notifySubscription (Observable.js:152)
    at onNotify (Observable.js:196)
    at SubscriptionObserver.next (Observable.js:248)
    at index.js:171
bug blocking

Most helpful comment

Let's not keep reacting same, it will make it harder for people to find the solution provided by @dinidu01. I'll have a PR ready to fix this tonight, let's resort to an emoji or something on OP's post if you are experiencing the same issue.

Sorry for the inconvenience, we'll work actively to fix this asap.

All 24 comments

I'm seeing this as well.

Yup seeing this too

Same here...

As a workaround
package.json

"resolutions": {
    "apollo-link-dedup": "1.0.15"
  }
rm -rf node_modules
npx npm-force-resolutions
npm install

Check older version of apollo-link-dedup was installed
npm ls apollo-link-dedup

@dinidu01 this is the first time I see that "resolutions" key in use. Would you mind explaining why this works? Couldn't I just pin the version of the package to "1.0.15" and get the same effect?

That means that your subscribers are undefined, anything specific you did to achieve this?

@JoviDeCroock for me it happened magically over night without me changing any code. I suspect there is a bug in the zen-observable release that was released 5 hours ago.

Same here, I debug it and found the missing key is an @client query

https://github.com/apollographql/apollo-link/blob/master/packages/apollo-link-dedup/src/dedupLink.ts#L65

This is a mistake I think, so we get a subscriber and call .delete on it. When the key has no result we shouldn't call anything on it.

same here

TypeError: Cannot read property 'delete' of undefined
    at /xxx/node_modules/apollo-link-dedup/src/dedupLink.ts:66:36

Same here. Breaking our builds.

Same here :(

same here, take me couple hours to figure it out from cicd flow :(

Let's not keep reacting same, it will make it harder for people to find the solution provided by @dinidu01. I'll have a PR ready to fix this tonight, let's resort to an emoji or something on OP's post if you are experiencing the same issue.

Sorry for the inconvenience, we'll work actively to fix this asap.

/usr/src/app/node_modules/zen-observable/lib/Observable.js:63
      throw e;
      ^

TypeError: Cannot read property 'delete' of undefined
    at /usr/src/app/node_modules/apollo-link-dedup/lib/dedupLink.js:48:47
    at cleanupSubscription (/usr/src/app/node_modules/zen-observable/lib/Observable.js:90:7)
    at notifySubscription (/usr/src/app/node_modules/zen-observable/lib/Observable.js:145:41)
    at onNotify (/usr/src/app/node_modules/zen-observable/lib/Observable.js:165:3)
    at SubscriptionObserver.complete (/usr/src/app/node_modules/zen-observable/lib/Observable.js:229:7)
    at /usr/src/app/node_modules/apollo-link-dedup/lib/dedupLink.js:34:81
    at Set.forEach (<anonymous>)
    at Object.next (/usr/src/app/node_modules/apollo-link-dedup/lib/dedupLink.js:34:45)
    at notifySubscription (/usr/src/app/node_modules/zen-observable/lib/Observable.js:130:18)
    at onNotify (/usr/src/app/node_modules/zen-observable/lib/Observable.js:165:3)

@dinidu01 this is the first time I see that "resolutions" key in use. Would you mind explaining why this works? Couldn't I just pin the version of the package to "1.0.15" and get the same effect?

@mbrochh No, you couldn't. In this case y'll have more that one package with different versions. Try yarn add [email protected] and then yarn why apollo-link-dedup after. Result:

[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "[email protected]"
info Has been hoisted to "apollo-link-dedup"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "560KB"
info Disk size with unique dependencies: "1.67MB"
info Disk size with transitive dependencies: "3.48MB"
info Number of shared dependencies: 7
=> Found "apollo-client#[email protected]"
info This module exists because "apollo-client" depends on it.
info Disk size without dependencies: "540KB"
info Disk size with unique dependencies: "1.74MB"
info Disk size with transitive dependencies: "3.46MB"
info Number of shared dependencies: 7

With "resolutions" you got one package (on install after remove node_modules).

A fix for this is coming momentarily - sorry for the headache all!

[email protected] should now fix this (thanks @JoviDeCroock!).

Just a heads up about apollo-link-dedup - this functionality is being merged into Apollo Client itself. This package will stay as is, but if you're using Apollo Client you're automatically using this package behind the scenes. When Apollo Client 2.6.0 is released, this will no longer be the case (since AC 2.6 will provide its own modified link deduplication functionality).

Awesome, thanks for such quick fix guys!

@hwillson

Unfortunately, after upgrading my dependencies, I'm still seeing this error, although with a slightly different stack trace. It seems to appear after every query.

My dependencies are:

    "apollo-cache-inmemory": "^1.5.1",
    "apollo-client": "^2.5.1",
    "apollo-link": "^1.2.10",
    "apollo-link-dedup": "^1.0.18",
    "apollo-link-error": "^1.1.9",
    "apollo-link-http": "^1.5.13",

The stack trace is:

bundle.esm.js:47 Uncaught TypeError: Cannot read property 'delete' of undefined
    at bundle.esm.js:47
    at cleanupSubscription (Observable.js:90)
    at notifySubscription (Observable.js:145)
    at onNotify (Observable.js:165)
    at SubscriptionObserver.complete (Observable.js:229)
    at bundle.esm.js:33
    at Set.forEach (<anonymous>)
    at Object.next (bundle.esm.js:33)
    at notifySubscription (Observable.js:130)
    at onNotify (Observable.js:165)
    at SubscriptionObserver.next (Observable.js:219)
    at bundle.esm.js:76

Try adding: "resolutions": {
"apollo-link-dedup": "1.0.18"
}

Thanks @JoviDeCroock! That did the trick.

For anyone who runs into this in the future before 2.6, a summary of the fix:

1) Install [email protected]
2) Add the following to your package.json:

"resolutions": {
  "apollo-link-dedup": "1.0.18"
}

This will resolve the apollo-link-dedup dependency within Apollo Client (currently at 1.0.17), to 1.0.18 with the fix.

One of your dependencies is pulling apollo-link-dedup to the wrong dependency that's the danger of using ^ instead of just fixing your version.

It seems like it was apollo client itself. Running npm ls apollo-link-dedup before adding the resolutions to my package.json gave me:

├─┬ [email protected]
│ └── [email protected]
Was this page helpful?
0 / 5 - 0 ratings