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

@apollo/client 3.4.0-beta.6 breaks Next.js setup with "TypeError: class constructors must be invoked with 'new'" #7635

Closed
rriski opened this issue Jan 31, 2021 · 1 comment
Assignees

Comments

@rriski
Copy link

rriski commented Jan 31, 2021

Intended outcome:

Upgrading to @apollo/client 3.4.0-beta.6 breaks with TypeError: class constructors must be invoked with 'new' using Next.js. Works fine with @apollo/client 3.4.0-beta.4. Most likely due to changes in PR #7615.

Actual outcome:
TypeError: class constructors must be invoked with 'new'

How to reproduce the issue:
Clone repo https://github.com/rriski/with-apollo. Run with yarn dev. Works with 3.4.0-beta.4, breaks with 3.4.0-beta.6 -> TypeError: class constructors must be invoked with 'new'.

Versions

npx: installed 1 in 1.208s

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 14.8.0 - ~/.nvm/versions/node/v14.8.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.7 - ~/.nvm/versions/node/v14.8.0/bin/npm
  Browsers:
    Chrome: 88.0.4324.96
    Safari: 14.0.2
@benjamn benjamn self-assigned this Feb 1, 2021
benjamn added a commit that referenced this issue Feb 2, 2021
Now that the zen-observable-ts package has the ability to export
Observable as a native class (#7615), we need to be careful when extending
Observable using classes (like ObservableQuery and Concast) that have been
compiled to ES5 constructor functions (rather than native classes),
because the generated _super.call(this, subscriber) code throws when
_super is a native class constructor (#7635).

Rather than attempting to change the way the TypeScript compiler
transforms super(subscriber) calls, this commit wraps Observable.call and
Observable.apply to work as expected, by using Reflect.construct to invoke
the superclass constructor correctly, when the Reflect API is available:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct

Another option would be to ship native class syntax with @apollo/client,
by changing the "target" in tsconfig.json from "es5" to "es2015" or later,
so that consumers of @apollo/client would be forced to compile native
class syntax however they see fit. That would be a more disruptive change,
in part because it would prevent subclassing Apollo Client-defined classes
using anything other than native class syntax and/or the Reflect.construct
API, which is the very same problem this commit is trying to fix for the
Observable class.
@hwillson
Copy link
Member

This should be fixed in the latest @apollo/client@beta. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants