TypeError: Illegal constructor when trying to create a new instance of a class of another script file

I created a library of about 25 custom Web Components using LitElement + WebPack. The library contains components (e.g. context menus component) and views (e.g. custom table which also uses the context menu component).

So far, all components and codes were in one javascript file. To make the package more modular, I created a second entry point. Now all ui-components have their dependency graph as well as the special matrix table view.

entry: {
  'ui-components': './src/index.js',
  'view-matrix': './src/view-matrix.js'
},

In WebPack (v4) I’m using splitChunks Optimization:

optimization: {
    splitChunks: {
        chunks: 'all',
    },
}

If I now want to instantiate a ui component (defined and imported in /src/index.js) in view-matrix.js, I’m getting the following error.

1) Instantiation (view-matrix.js:31)

import {MwNavigationContextmenu} from "./components/navigations/mw-navigation-contextmenu";
    
let contextMenu = new MwNavigationContextmenu();

2) Error Message

TypeError: Illegal constructor (view-matrix.js:31)

👉 Instantiating the same line of code in index.js works perfectly fine.

👉 I made sure, MwNavigationContextmenu was defined as a custom web component before:

window.customElements.define('mw-navigation-contextmenu', MwNavigationContextmenu);

3) MwNavigationContextmenu definition

./components/navigations/mw-navigation-contextmenu

import { MwNavigationContextmenu } from './src/MwNavigationContextmenu.js';

window.customElements.define('mw-navigation-contextmenu', MwNavigationContextmenu);

./src/MwNavigationContextmenu.js

import {html, LitElement} from 'lit-element';

export class MwNavigationContextmenu extends LitElement {
  static get properties() {
    return {
      // defined props
      // hasbutton: {type:Boolean},
    };
  }

  constructor() {
    super();
    // property defaults following
    // this.hasbutton = true;
  }

  render() {
    return html`
      Render context menu…
    `;
  }
}

So there problem is kind of that MwNavigationContextmenu was defined in index.js and view-matrix.js can’t instantiate classes then for whatever reason.

146 thoughts on “TypeError: Illegal constructor when trying to create a new instance of a class of another script file”

  1. whoah this weblog is excellent i love studying
    your posts. Keep up the good work! You recognize, many persons are looking round for this information, you could help
    them greatly.

    Reply
  2. An outstanding share! I have just forwarded this onto a friend who had
    been conducting a little research on this. And he actually ordered me lunch because I discovered it for
    him… lol. So let me reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending time to talk about this subject here on your website.

    Reply
  3. Today, I went to the beach with my kids. I found a
    sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to
    her ear and screamed. There was a hermit crab inside and
    it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell
    someone!

    Reply
  4. Hello! I know this is kinda off topic but I was
    wondering which blog platform are you using for this website?
    I’m getting fed up of WordPress because I’ve had
    issues with hackers and I’m looking at options for another platform.
    I would be great if you could point me in the direction of a good platform.

    Reply
  5. This is the perfect webpage for anyone who would like to find out about this topic.

    You realize a whole lot its almost hard to
    argue with you (not that I personally will need to…HaHa).
    You certainly put a brand new spin on a topic that’s been discussed for many years.
    Excellent stuff, just wonderful!

    Reply
  6. What i do not realize is in reality how you are now not really
    much more smartly-liked than you may be now. You’re so intelligent.
    You know thus considerably on the subject of this
    topic, produced me individually imagine it from so many various angles.
    Its like women and men aren’t fascinated unless it is something to accomplish with Lady gaga!
    Your individual stuffs outstanding. At all times take care of it
    up!

    Reply
  7. Hi would you mind sharing which blog platform you’re working with?

    I’m looking to start my own blog soon but I’m having
    a hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design and style seems different
    then most blogs and I’m looking for something completely unique.
    P.S Apologies for being off-topic but I had to ask! asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr

    Reply
  8. hey there and thank you for your information – I’ve definitely picked up anything new from right
    here. I did however expertise a few technical issues using this web site, since I experienced to reload the site a lot of times previous
    to I could get it to load correctly. I had been wondering if your web hosting is OK?
    Not that I am complaining, but slow loading instances times will
    sometimes affect your placement in google and could damage your quality score if advertising
    and marketing with Adwords. Well I am adding this RSS to
    my email and could look out for much more of your respective
    fascinating content. Make sure you update this again very soon. ps4 games https://bit.ly/3nkdKIi ps4

    Reply
  9. Howdy would you mind sharing which blog platform you’re using?
    I’m looking to start my own blog soon but I’m having a tough
    time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design and style seems different then most blogs and
    I’m looking for something completely unique.

    P.S My apologies for getting off-topic but I had to ask!
    quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

    Reply
  10. I had a wonderful shopping test with azithromycintok.com. They answered all my questions patiently and directed me to the right product. I also did a price juxtaposition, and their price was significantly cheaper than the other websites I visited. I pleasure boutique here again.

    Reply
  11. Pingback: tizanidine 5.2
  12. Pingback: 150 mg clomid
  13. Pingback: clomid drug cost
  14. Pingback: tamoxifen drug
  15. Pingback: aralen 50mg
  16. Pingback: new covid drug
  17. Hey would you mind sharing which blog platform you’re working with?

    I’m planning to start my own blog in the near future but I’m having a
    tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout
    seems different then most blogs and I’m looking for something
    completely unique. P.S Sorry for getting off-topic but I had to ask!

    Reply
  18. I’ll right away snatch your rss feed as I can not find
    your email subscription hyperlink or newsletter service.
    Do you’ve any? Kindly let me realize in order that I may subscribe.
    Thanks.

    Reply
  19. Your style is so unique compared to other people I have read stuff from.
    I appreciate you for posting when you’ve got the opportunity, Guess
    I will just bookmark this web site.

    Reply
  20. I’m amazed, I have to admit. Seldom do I come across a blog that’s equally educative and entertaining, and without a doubt, you’ve hit the nail on the head.
    The issue is something which not enough people are speaking intelligently about.
    I’m very happy I stumbled across this during my search for something concerning
    this.

    Reply
  21. whoah this weblog is great i really like reading your articles.
    Keep up the great work! You realize, many individuals
    are hunting round for this info, you could aid them greatly.

    Reply
  22. What i don’t realize is actually how you’re not actually a lot more well-appreciated than you might be now.
    You are very intelligent. You recognize therefore considerably relating to
    this topic, produced me in my opinion believe
    it from numerous various angles. Its like women and men aren’t
    involved unless it’s one thing to accomplish with Lady gaga!
    Your own stuffs nice. At all times care for it up!

    Reply
  23. I’m really enjoying the design and layout of your
    site. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you
    hire out a developer to create your theme?
    Excellent work!

    Reply
  24. I think what you typed made a lot of sense.
    But, think on this, suppose you added a little content?

    I am not suggesting your information is not solid., however suppose you added
    a post title that makes people want more? I mean TypeError: Illegal constructor when trying
    to create a new instance of a class of another
    script file – JavaScript Help is a little boring.

    You might peek at Yahoo’s home page and watch how they create news titles to get viewers
    interested. You might try adding a video or a related pic
    or two to grab people interested about everything’ve got to say.
    Just my opinion, it would bring your posts a little livelier.

    Reply
  25. I don’t even know the way I ended up here, however I assumed this post was once great.

    I do not understand who you are however certainly
    you are going to a famous blogger should you aren’t
    already. Cheers!

    Reply

Leave a Comment