缺少 lit 包中的装饰器说明符

huangapple go评论66阅读模式
英文:

Missing decorators specifier in lit package

问题

I have installed lit package via npm, then i replaced my-element.ts file with my own .ts file and also updated the package.json file with the new .ts file

Error details

import { LitElement, html, css } from "lit";
import { customElement, property } from "lit/decorators";

@customElement('sample_project')
export class SampleProject extends LitElement {
    static styles = css`p {color: blue}`;

    @property()
    name = 'Intro';

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

I tried running the component on local host with npm run dev, I get an error that says it's missing ./decorators specifier in 'lit' package but weird because I have installed web dev server npm to try to solve the problem.

expecting this to run and render Hello intro only, very basic

英文:

I have installed lit package via npm, then i replaced my-element.ts file with my own .ts file and also updated the package.json file with the new .ts file

Error details

`import { LitElement,html,css } from "lit";
import { customElement, property } from "lit/decorators";

@customElement('sample_project')
export class SampleProject extends LitElement {
static styles = cssp {color:blue};

@property()
name = &#39;Intro&#39;;

render(){
    return html`&lt;p&gt;Hello, ${this.name}!&lt;/p&gt;`;
}

}`

I tried running the component on local host with npm run dev, I get an error that says it's missing ./decorators specifier in 'lit' package but weird because I have installed web dev server npm to try to solve the problem.

expecting this to run and render Hello intro only, very basic

答案1

得分: 0

"Double check manually if ./node_modules/lit/decorators exists. If it does, try to provide the import using the full directory path."

英文:

It seems like the decorators directory cannot be found in the lit package you installed, therefore Vite complains that the path does not exist.

Double check manually if ./node_modules/lit/decorators exists. If it does, try to provide the import using the full directory path.

答案2

得分: 0

你需要指定扩展名。

import { customElement, property } from "lit/decorators.js";

包的导出是在 package.json 中使用 .js 扩展名定义的,所以模块必须与之匹配才能解析。

关于为什么 lit 包这样做的更多信息,请参阅此处:https://lit.dev/docs/tools/publishing/#include-file-extensions-in-import-specifiers

英文:

You need to specify the extension.

import { customElement, property } from &quot;lit/decorators.js&quot;;

The package exports is defined with the .js extension in the package.json https://github.com/lit/lit/blob/b0c3f82ef0f97326a205e77e7e1043b75a5cc53f/packages/lit/package.json#L28 so it must match that for the module to be resolved.

You can read more about why the lit package does that here: https://lit.dev/docs/tools/publishing/#include-file-extensions-in-import-specifiers

huangapple
  • 本文由 发表于 2023年2月23日 21:11:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545315.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定