Closed sgammon closed 1 year ago
cc / @justinfagnani who may be able to shed some light as well... this feels like a simple config issue, but being that the React adapter is in labs, maybe this is new?
Uncaught TypeError: Class constructor LitElement cannot be invoked without 'new'
This usually means that a subclass of LitElement has been compiled to no longer be a real class (ie, compiled to an "ES5 class") and is invoking the LitElement constructor like LitElement.call(this)
. That doesn't work with real classes.
The solution is to either compile all of your libraries to ES5 (and use the custom elements es5 adapter), or none of them. Unless you're supporting IE11 there's really no reason to compile to ES5 anymore.
@justinfagnani thank you for the quick reply! I owe you a beer or a coffee by now, you have helped me so many times! 😁
I understand that ES5 transpilation isn't needed anymore, but I guess in this case I'm unclear how to prevent it. Perhaps that points to this being a configuration issue, I'll try and pursue with Nx. If you happen to know what Babel or Webpack settings are needed to bump up to ES6+ or know where I might find those I'm happy to dig in and see if I can apply to my case.
(For context, I've used the OpenWC method of integrating Lit with Storybook before, but I know that package takes a rather aggressive stance at packaging everything with ESM, and so ships its own pre-packaged Storybook. Now that I'm in React land, I'm unclear how to use Storybook easily with Lit)
I'm facing same problem, but it is not related with Lit - I'm trying to extends three.js classes. I can't seem to be able switch away from compilation to ES5. 🤷♂️ I tried changing TS target to anything else - no luck.
I was facing the same problem, but with a simple web (js based) app. To fix, I used the "swc" compiler for building, and created a .swcrc file in my app (apps/my-app) directory. I then copied the default json (https://swc.rs/docs/configuration/swcrc) into this file and updated the target to es2017 (I also had to remove the comment).
We also have the exact same setup, we included some of our webcomponents in the preview.js
.
And get the same error: Class constructor LitElement cannot be invoked without 'new'
I'm facing same problem, but it is not related with Lit. In my code I extend a class from a third party library and got an error as described in this topic.
To fix this I provide a .babelrc
file with a custom configuration in the package/.storybook
folder and it fix an error.
For my project I use next babel setup:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "3"
}
],
"@babel/preset-typescript",
"@babel/preset-react"
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"version": "legacy"
}
]
]
}
Hello all! Since there seem to be workarounds to this issue, I will be closing this issue! Also, don't forget to try out the latest version of Nx, maybe this is fixed natively.
Please feel free to ping me and I will reopen this issue, if you think it's still a problem!
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
Hey there Nx devs. I'm new to Nx but loving it so far. When I try to use Lit with the React stack, however, I'm unclear about how to properly configure Nx/Babel/Webpack to work with Lit and Storybook.
This actually may be something simple in Babel or Webpack, based on some prior related issues, all of which point to
es5
/ other transpilation settings. However, being new to Nx, I'm unable to reconcile these hints with what I should do in.storybook
to get things to interoperate correctly. Any help would be deeply appreciated as Nx looks awesome and we'd love to adopt.Expected Behavior
Through the
@lit-labs/react
adapter, I should theoretically be able to define a Lit component, wrap it in a React component, and then display it in Storybook as a React componentSteps to Reproduce
Please find a Github repo here reproducing these steps
npx create-nx-workspace@latest --preset=react --packageManager=yarn
test
test
styled-components
no
cd test && nx build
yarn add --dev @nrwl/storybook
nx g @nrwl/react:storybook-configuration test
, provide answerstrue
true
true
nx run test:storybook
. All should be fine.yarn add lit
Failure Logs
Environment