-
Notifications
You must be signed in to change notification settings - Fork 319
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
Uncaught TypeError: Class constructor LitElement cannot be invoked without 'new' #54
Comments
Is it being compiled to es5 without adding the custom-elements-es5-adapter.js file? |
@jsilvermist Good idea! Unfortunately, after adding it the same error persists. |
@rjsteinert The Now, I tried to add the loader and adapter to |
@TimvdLippe I found a ticket relared to ES modules in the webcomponentjs issue queue webcomponents/webcomponentsjs#882 This not working in Firefox is definitely a concern and as you said related to the polyfills not loading. Does Chrome need the polyfills to make this work? I'm assuming not, and if that's the case then I wonder what is up with this error |
@rjsteinert Chrome does not need the polyfill, but does require the adapter to be loaded. When I ran your project, I did not see the adapter being loaded. Therefore it would break in Chrome, as Chrome requires the adapter to be loaded if you define your custom elements in ES5. |
I'm getting the same error with the |
Same behavior with index.html:
App.js:
|
same here,
it seems like the adapter is not... adapting. I'm also using code-splitting via Webpack but trying to going back to single-bundle-file didn't changed the result. any clue about this? |
Related to Polymer/tools#398 |
From what I can tell, the issue is years-old in Babel, and is a bug preventing the usage of extended native classes without |
Hey @rjsteinert, do you need it to be downtranspiled to ES5? I changed my Cheeers, |
I experienced the same error when transpiling using webpack and babel-preset-env.
then change the option in your webpack configuration to es2017 options: {
presets: ['es2017']
} or in .babelrc {
"presets": ["es2017"]
} |
Fixed with babel/babel#8501 and included in Babel 7 release, so the issue can be closed. |
@dkundel Changing Agnular's |
What is the real resolution to this? So much confusion across the issues. |
I’m assuming the new Babel update will fix this. Waiting on support Babel 7 in Parcel, haha. Until then, I guess you could use Webpack? |
I am already on Webpack actually :/ |
The 7.0.0 stable release of Babel works properly as I mentioned above. You can also find a config example here: https://github.com/web-padawan/lit-components |
Thanks @web-padawan, that was helpful. I wasn't willing to let go of "preset-env" just yet. In summary, the issue is... ES6 classes must only be called with A suggested strategy is to have separate babel builds:
Then in production server needs to figure out whether to serve 1 or 2, which is admittedly more complexity. (Or just tell your customers to download Chrome) For now I'll go with 1 and configure 2 later. |
@ernsheong if you’re interested in a world that combines 1 and 2 while making sure that users on each side get the best code for them, you might be interested in something like https://philipwalton.com/articles/deploying-es2015-code-in-production-today/ It’s looking really good for the applications I’m working on, which use |
@Westbrook thanks for sharing the article, definitely looks promising (and more doable)! I like this other article from the same author too: https://philipwalton.com/articles/loading-polyfills-only-when-needed/ (from which I got the idea of punishing older browsers rather than newer ones) |
Hi,
import { storiesOf } from '@storybook/html';
import './counter-element';
storiesOf('CounterElement', module)
.add('default', () => `<counter-element clicks="3" 1alue="1"></counter-element>`); But then I got the error |
@tonai I'm using LitElement & Storybook with |
@moebiusmania What version of I just switch my above story using My storybook config file import { configure } from '@storybook/polymer';
const req = require.context('../src', true, /\.stories\.js$/);
function loadStories() {
req.keys().forEach((filename) => req(filename))
}
configure(loadStories, module); I also tried to initialize the storybook using the cli |
@tonai 4.0.2, you can check it out here https://github.com/bitrockteam/amber-components , hope it helps. |
If you are seeing this error, you are likely in need of two important babel plugins. Additionally if you have ES6 code inside node_modules you MUST include them in your babel loader. LitElement library itself is ES6. I was having this issue with Gatsby. Gatsby 2 by default includes code from all node_modules so all I had to do was Install these modules and add this to my .babelrc, the order is important.
For Gatsby, I did this by following the instructions at https://www.gatsbyjs.org/docs/babel/#how-to-use-a-custom-babelrc-file |
It solves the problem for me, but for some reason it prevents arrow functions from being transpiled. In other words, arrow syntax is not replaced neither in Here's a snippet from
|
THIS works, and the problem happens even on Chrome 75. So I don't see why this isn't included by default. |
@mihaisavezi Included where by default? |
Has anyone solved this issue yet? I have tried everything in this thread and I'm still seeing this error in Chrome if I transpile my LitElements down to ES5 even when the I tried @Manidos 's Webpack config:
and the error goes away in Chrome. But upon further inspection I believe that's because the If you rewrite the config to the following: I have tried including the @web-padawan do you think this is a Babel issue again? I am using the following config:
and my .babelrc is as follows:
Any guidance would be greatly appreciated. I have enjoyed my experience with LitElement so far and would really like to adopt it into some of my projects. I am currently just excluding the LitElements from my babel-loader in order to continue building, but I would love to put this issue to bed because at some point I will need to properly support IE11. |
@n-devr consider using webpack-babel-multi-target-plugin which outputs ES module bundle + ES5 "nomodule" bundle for legacy browsers. We are using it and it works nice. |
Thanks for your reply @web-padawan - I did see that solution referenced in other issues and even found the open-wc compatibility docs as well. The concept sounds great and I like the idea of reducing the bundle size for modern browsers, but with the I'm happy to create a new repo to isolate the problem and make a new issue for it if that would help. It might also save people some time to know that it's not a viable option. |
@n-devr you only need ES5 adapter if you transpile to ES5. Otherwise, you should not include it. Also, you can set Regarding |
Thanks for your time and quick reply @web-padawan ! My goal is to have a single bundle transpiled to ES5 that I serve to all browsers. Sorry if the |
@n-devr Sir Did you found any solution? with webpack targeting ie 11? |
@sdyalor my issue is not the IE11 support in and of itself - if you use the webpack and babel config I referenced above you should be able to generate a bundle that is transpiled down to ES5 and works in IE11. Unfortunately, that same bundle does not work in Chrome, and the @web-padawan I also want to reiterate my offer to create a public repo with a simple project to demonstrate the issue. It seems like there are a good number of people who are having this issue, and if you think it would help the team to debug and potentially solve the problem I'm happy to help. |
@n-devr So, excluding Internet Explorer and knowing that What the formula to cover wide range of browsers is? When I target to |
@n-devr if you create an example repository, I could take a look. However, please keep in mind the following problems:
As a result, developer experience with IE11 is horrible and the apps are too slow. |
Sorry to add to a closed thread but what is the solution to this for TypeScript and Rollup? Most of what I see here is for babel and webpack. I've tried adding this to my tsconfig
Rollup config looks like this
What should I change? |
@sslotsky do you need to support IE11? If not, change |
Encountered the same problem and not resolved |
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? |
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 |
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 |
@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. |
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? |
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 theng new
command.If you want to poke at it, run the following commands...
The text was updated successfully, but these errors were encountered: