yysun/apprun

Uncaught TypeError: Class constructor M cannot be invoked without 'new'

commenthol opened this issue · 4 comments

Hi @yysun, I am trying to run a sample from the tutorial. But I am struggling badly with this code.

main.tsx

import app, {Component} from 'apprun';

class Counter extends Component {
  state = '';
  view = state => <div/>;
  update = {};
}

const element = document.getElementById('my-app');
app.render(element, <Counter />);

Which gives me a

main.tsx:3 Uncaught TypeError: Class constructor M cannot be invoked without 'new'
    at new Counter (main.tsx:3)
    at i (createComponent.tsx:12)
    at t (createComponent.tsx:37)
    at u (vdom-my.ts:43)
    at t../node_modules/apprun/dist/apprun.esm.js.s.render (vdom.ts:3)
    at Module../src/main.tsx (main.tsx:10)
    at __webpack_require__ (bootstrap:19)
    at Object.0 (main.tsx:10)
    at __webpack_require__ (bootstrap:19)
    at bootstrap:83

I am using apprun@2.23.1 but @3.22.2 or @2.22.2 gives me the same result. The initial app was created with apprun --init

yysun commented

Default is es5 - after changing target to es2015 all is fine with version 2.
Would it be possible to explain what are the different versions and what is their main difference?
Maybe I have overseen something in the documentation, so a small hint is appreciated.
Thanks for your efforts.

yysun commented

In the past, the AppRun default version on npm is 1.x. The CLI creates tsconfig for es5. And use --es6 option to create tsconfig for 2.x.

On Feb 21, 2020, I switched the default version on npm from 1.x to 2.x. And made the CLI creates tsconfig for es2015. And use --es5 option for 1.x.

When upgrading old projects to use the latest version, we need to modify the tsconfig from es5 to es2015.

Explained the changes in the [CHANGLOG]. (https://github.com/yysun/apprun/blob/master/CHANGELOG.md)

  • apprun@es5: 1.x, stable, es5
  • apprun@latest: 2.x, stable, es2015, web component
  • apprun@next: 3.x, dev, es2015, lit-html

I will add the version information to README as well.

Thanks for the clarification.