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

TypeError: Class constructor Presenter cannot be invoked without 'new' #75

Closed
hult opened this issue Feb 5, 2020 · 9 comments
Closed

Comments

@hult
Copy link
Contributor

hult commented Feb 5, 2020

Hi @javve @jede et. al.!

We've been using yayson in ES6 like this

import yayson from 'yayson'
const y = yayson({adapter: 'default'})
const Presenter = y.Presenter

class MyPresenter extends Presenter {
  // ...
}

class AnotherPresenter extends MyPresenter {
  attributes(instance) {
    // We don't want to send the image to the server
    var attrs = super.attributes(instance)
    delete attrs['image']
    return attrs
  }
}
AnotherPresenter.prototype.type = 'another_type'

And it has worked well up until version 2.0.8. Starting in yayson 2.0.9, we get the error

TypeError: Class constructor Presenter cannot be invoked without 'new'

      59 |     delete attrs['image']
      60 |     return attrs
    > 61 |   }
         |    ^
      62 | }

Something has changed. Any ideas?

@jede
Copy link
Contributor

jede commented Feb 6, 2020

Hm, interesting. 2.0.9 was a veryminor change, there is however an effort to remove CoffeeScript. Maybe try out that branch? #69

@hult
Copy link
Contributor Author

hult commented Feb 6, 2020

2.0.9 was a very minor change

Yeah I saw, but 2.0.8 was a while ago, and quite a few dependencies were updated since.

Maybe try out that branch?

Will do!

#69

Nice.

@hult
Copy link
Contributor Author

hult commented Feb 6, 2020

(Sorry for not understanding how coffeescript modules work at all. :( )

If I yarn add https://github.com/confetti/yayson.git#decaffeinate, I get the exact same error as above.

If I try to install any commit between 2.0.8 and 2.0.9 (to pinpoint when the error appeared), I instead get the error Cannot find module 'yayson' (I guess it isn't automatically transpiled?)

@jede
Copy link
Contributor

jede commented Feb 6, 2020

I think there is a release issue that @javve tried to fix with v2.0.10-quickfix, but I'm not sure it worked. Are you running your example in the browser (and in that case are you using webpack or something else?) or in node?

@hult
Copy link
Contributor Author

hult commented Feb 7, 2020

This is for the browser, with webpack (4.41.5). 2.0.10-quickfix didn't fix my problem unfortunately.

@hult
Copy link
Contributor Author

hult commented Feb 7, 2020

(Also, I'm perfectly happy with 2.0.8, don't work too hard on this. :))

@jede
Copy link
Contributor

jede commented Apr 16, 2021

This probably has to do with extending non native ES6 classes. Its wierd that it worked pre 2.0.9 though. I think this will be solved in 3.0 when everything will be native classes :) And I really havn't been working hard on this! 😂

@hult
Copy link
Contributor Author

hult commented Apr 16, 2021 via email

@jede
Copy link
Contributor

jede commented Feb 2, 2023

A brand new 3.0 version is finally out 😅

@jede jede closed this as completed Feb 2, 2023
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

No branches or pull requests

2 participants