question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Class-based TypeScript component does not get initialized properly

See original GitHub issue

Hi there!

I am trying to run a minimal configuration using vue-custom-element and TypeScript. Unfortunately, I get this error when trying to load the html file in a browser:

vue.esm.js?a026:4798 Uncaught TypeError: Cannot read property '_init' of undefined
    at VueComponent (vue.esm.js?a026:4798)
    at HTMLElement.connectedCallback (vue-custom-element.esm.js?c894:430)
    at HTMLElement.connectedCallback (vue-custom-element.esm.js?c894:57)
    at registerCustomElement (vue-custom-element.esm.js?c894:99)
    at Function.vueCustomElement [as customElement] (vue-custom-element.esm.js?c894:423)
    at eval (index.ts?ffb4:7)
    at Object.<anonymous> (build.js:1)
    at g (build.js:1)
    at build.js:1
    at build.js:1

I tried to strip away everything unimportant but am stuck at this point. Any ideas what might went wrong?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
karol-fcommented, Apr 11, 2018

@sonovice Hi, you are right. It’s because vue-class-component returns constructor. I checked and to make it works you have to use:

Vue.customElement('hello-component', (new HelloComponent()).$options);

Hope it will work now. Regards!

1reaction
sonovicecommented, Apr 11, 2018

… my bad. Thank you so much! It works now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript class properties not being initialized - Stack Overflow
The problem is the order of execution. Field initializers are just syntactic sugar for fields assigned in the constructor, but the first ...
Read more >
Class Components - React TypeScript Cheatsheets
Within TypeScript, React.Component is a generic type (aka React.Component), so you want to provide it with (optional) prop and state type parameters:
Read more >
How to create React components with TypeScript
We'll typically use constructors to initialize our class component's state. Unfortunately, the React class won't know the type of our props ...
Read more >
How to properly define state in React components - ITNEXT
If you have been using React, there is a 100% chance that you know the pattern of initializing a component's state in it's...
Read more >
TypeScript and React: Components - fettblog.eu
Components are at the heart of React. Let's see what we can do to get better error handling and tooling for them! In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found