lit / lit-element

LEGACY REPO. This repository is for maintenance of the legacy LitElement library. The LitElement base class is now part of the Lit library, which is developed in the lit monorepo.
https://lit-element.polymer-project.org
BSD 3-Clause "New" or "Revised" License
4.49k stars 319 forks source link

Uncaught TypeError: Class constructor LitElement cannot be invoked without 'new' #54

Closed rjcorwin closed 5 years ago

rjcorwin commented 6 years ago

I'm trying out Lit Element in a vanilla Angular 6 project and running into Uncaught TypeError: Class constructor LitElement cannot be invoked without 'new' when trying out the hello world lit element example. This commit shows how I added webcomponentjs / litelement packages, allow custom schema in angular, declare the my-element LitElement example, and then use that element in the app. That commit was made right after running the ng new command.

screen shot 2018-05-11 at 3 33 16 pm

If you want to poke at it, run the following commands...

git clone https://github.com/rjsteinert/angular-with-lit-element.git
cd angular-with-list-element
npm install
npm start
justinfagnani commented 4 years ago

@sslotsky do you need to support IE11? If not, change target: 'es5' in the Rollup config.

huangjihua commented 4 years ago

Encountered the same problem and not resolved

ghost commented 3 years ago

I'm using typescript and currently compiling to es6 but I need to support IE11 so eventually must switch to compiling to es5. Is there a solution for this yet?

justinfagnani commented 3 years ago

There has been a solution - compile your app to ES5 and either serve ES5 to IE11 and ES2017+ to Chrome, or serve ES5 to all browsers and include the custom-elements-es5-adapterjs to all ES5 to construct HTML elements: https://github.com/webcomponents/polyfills/tree/master/packages/webcomponentsjs#custom-elements-es5-adapterjs

ghost commented 3 years ago

I've done that by importing the following files in my rollup.js input:

import '@webcomponents/webcomponentsjs/webcomponents-loader.js';
import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js';
import 'lit/polyfill-support.js';

However, the Class constructor LitElement cannot be invoked without 'new' error still occurs on both Firefox and Chrome.

coolcorexix commented 2 months ago

is there any update on this? I tried to inject a web component to Youtube but this error was thrown

image
justinfagnani commented 2 months ago

@coolcorexix what kind of update are you looking for?

You either need to serve native classes to browsers (which you really should be doing - all browsers support classes now) or use the ES5 adapter: https://github.com/webcomponents/polyfills/tree/master/packages/webcomponentsjs#custom-elements-es5-adapterjs

coolcorexix commented 2 months ago

@coolcorexix what kind of update are you looking for?

You either need to serve native classes to browsers (which you really should be doing - all browsers support classes now) or use the ES5 adapter: https://github.com/webcomponents/polyfills/tree/master/packages/webcomponentsjs#custom-elements-es5-adapterjs

@justinfagnani I think I just did first option without knowing it

I have just solved the problem but I don't know if this can be simpified, the rough idea is like this:

The app I am talking about here is Youtube and I am injecting some UI by using a chrome extension. The whole process is very hacky so I just don't know if there is any other ways.

justinfagnani commented 2 months ago

The other way is to not compile away classes - use native classes.

coolcorexix commented 2 months ago

The other way is to not compile away classes - use native classes.

@justinfagnani I dont get what you mean, can you give me an example on how to do this?