英文:
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
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
`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 = '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
答案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 "lit/decorators.js";
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论