material-web: Components don't build properly with PolymerLabs/lit-element-build-rollup
Reproduce:
- Clone
https://github.com/PolymerLabs/lit-element-build-rollup - Update lit-element to latest (2.1.0)
- Build and verify that build works (it does đ)
- Add a component e.g.
npm install @material/mwc-button& import/add inmy-element(The element version is 0.5.0) - Clean and build
Two things happen:
- the build throws an error:
src/index.js â build/index.js...
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en#error-this-is-undefined
node_modules/@material/mwc-button/mwc-button.js
1: var __decorate = this && this.__decorate || function (decorators, target, key, desc) {
^
2: var c = arguments.length,
3: r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
...and 1 other occurrence
and 2. the app never renders - but throws an error in the console:
util.js:43 Uncaught TypeError: Cannot read property 'appendChild' of null
at detectEdgePseudoVarBug (util.js:43)
at supportsCssVariables (util.js:76)
at ripple-directive.js:26
Using the rollup script from https://open-wc.org/building/building-rollup.html works with the mwc-elements.
Also, other elements done with lit-element work (with the PolymerLabs/lit-element-build-rollup script).
Theory: The TypeScript compiler creates extra âboilerplateâ code for properties that is not compatible with the simple rollup script.
âcaptaincodemanâ (polymer slack) suggested adding this to the typescript config of the components (I didnât have a chance to try yet):
"noEmitHelpers": true,
"importHelpers": true,
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 15
It wonât break anything in MWC, but it will probably slightly increase bundle size (since transpiled classes are larger), and it makes the code a little less debuggable in the browser. I donât think this module actually has any imports/exports, itâs all side-effects. (But if it did, shipping ES5 transpiled code but with module syntax seems pretty odd, because you donât get the benefit of it working out-of-the-box in older browsers, but you also remove the possibility of serving smaller/faster code to modern browsers).
Sounds like this should have been a breaking change (totally my bad too, since we discussed it and I didnât know about this kind of use case), but TBH I donât think the fact that certain webpack configurations expect the âmoduleâ field to contain ES5 code is a compelling reason to shy away from publishing ES2015 to NPM. IMO if a user needs to support older browsers, they should have a build process that transpiles all their code, including dependencies, to ES5.
Iâll re-open this until the wicg-inert issue is fixed and we bump the dependency here.
@aomarks I filed a separate issue against the wicg-inert repo (see above) that appears to be a dependency for certain components. Does it make sense to reopen this issue until the dependency issue is resolved as youâll likely need to update package.json for any affected components?
For example, mwc-drawer wonât function within a Rollup bundle until this is resolved.
https://github.com/material-components/material-components-web-components/blob/master/packages/drawer/package.json#L23
Just released 0.8.0 with this change in it. Enjoy!
(Copying my comment from #323 here)