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 constructors must be invoked with 'new'" #54

Open
kud opened this issue Jun 13, 2019 · 7 comments
Open

TypeError: "class constructors must be invoked with 'new'" #54

kud opened this issue Jun 13, 2019 · 7 comments

Comments

@kud
Copy link
Contributor

kud commented Jun 13, 2019

Hello,

I'm doing this:

import React from "react"
import { Model } from 'coloquent'

class AppModel extends Model {
  getJsonApiBaseUrl() {
    return 'http://mysite.com/api'
  }
}

class Bill extends AppModel {
  jsonApiType = 'bills'
}


class SandboxPageMainPage extends React.Component {
  static propTypes = {}

  static defaultProps = {}

  state = {}

  componentDidMount() {
    const billModel = new Bill()

    billModel.get()
  }

  render() {
    return (
      <div>Coloquent test!</div>
    )
  }
}

export default SandboxPageMainPage

And I get this error:

TypeError: "class constructors must be invoked with 'new'"

Is it normal?

@mkamensky
Copy link

I have a similar problem. Is there any workaround?

@manuelantoncalvo
Copy link

I have the same problem in Angular

@kud
Copy link
Contributor Author

kud commented Jul 2, 2019

I wonder if it only works with typescript.

@DavidDuwaer
Copy link
Owner

@kud @ManuelCalvo @mkamensky Because Coloquent classes are compiled to ES6 classes, if you extend them in code that is compiled to ES5 you get this problem. Could it be that your projects are compiled to ES5?

@kud
Copy link
Contributor Author

kud commented Jul 25, 2019

That's right!

@DavidDuwaer DavidDuwaer changed the title ES6/webpack compliant? TypeError: "class constructors must be invoked with 'new'" Mar 23, 2020
@DavidDuwaer
Copy link
Owner

DavidDuwaer commented Mar 23, 2020

Maybe changing the compile target of this library to es5 would solve the problem, but I'm not sure if it's possible since the library relies on others extending its classes, for one. Would anyone care to try?

@ConsoleTVs
Copy link

ConsoleTVs commented Mar 23, 2020

I was using vue's typescript config and failed (didn't try again tho).

// tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "strict": true,
    "module": "es2015",
    "moduleResolution": "node"
  }
}

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

5 participants