Skip to content
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

bundle with ts decorators works fine with v0.17.19, not later #3889

Open
mindon opened this issue Aug 21, 2024 · 2 comments
Open

bundle with ts decorators works fine with v0.17.19, not later #3889

mindon opened this issue Aug 21, 2024 · 2 comments

Comments

@mindon
Copy link

mindon commented Aug 21, 2024

here's a ts example, which works fine with esbuild v0.17.19, but not any more with later esbuild v0.18.0 to v0.23.1

import { LitElement, html } from "https://cdn.skypack.dev/lit";
import { customElement, property } from "https://cdn.skypack.dev/lit/decorators";

@customElement("hello-world")
export class HelloWorld extends LitElement {

  @property({type: String})
  name = "";

  render() {
    return html`<p>Hello <strong>${this.name}</strong><p>`;
  }
}

the bundle js throw error Error: Unsupported decorator location: field

@mindon mindon changed the title decorators works fine with v0.17.19, not later bundle with ts decorators works fine with v0.17.19, not later Aug 21, 2024
@hyrious
Copy link

hyrious commented Aug 21, 2024

I believe this was because esbuild 0.18.0 adds support for vanilla JavaScript decorators (different from the "experimental" one invented by TypeScript). You just need to add the tsconfig "experimentalDecorators": true to enable the old behavior.


On the other hand, lit/decorators seems do support the new behavior: https://lit.dev/docs/components/decorators/#decorator-versions. You just have to add the accessor modifier to enable that.

@mindon
Copy link
Author

mindon commented Aug 26, 2024

I believe this was because esbuild 0.18.0 adds support for vanilla JavaScript decorators (different from the "experimental" one invented by TypeScript). You just need to add the tsconfig "experimentalDecorators": true to enable the old behavior.

On the other hand, lit/decorators seems do support the new behavior: https://lit.dev/docs/components/decorators/#decorator-versions. You just have to add the accessor modifier to enable that.

"experimentalDecorators" is true, add the accessor modifier to make it works!

but here https://lit.dev/docs/components/properties/#accessors-custom it says

If your class does not define accessors for a property, Lit will generate them, even if a superclass has defined the property or accessors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants