简体   繁体   English

为 lit-element 导入 JavaScript 在浏览器中出现 404 not found 错误

[英]JavaScript import for lit-element gives me 404 not found error in browser

I have installed lit-element via npm in ASP.NET MVC 5 solution.我已经在 ASP.NET MVC 5 解决方案中通过 npm 安装了 lit-element。 I am trying to create a starter tag as described in https://lit-element.polymer-project.org/guide/start guide.我正在尝试创建一个起始标记,如https://lit-element.polymer-project.org/guide/start指南中所述。 In browser, I get "GET http://localhost:64580/node_modules/lit-element/lit-element " net::ERR_ABORTED 404 (Not Found) in chrome.在浏览器中,我在 chrome 中得到“GET http://localhost:64580/node_modules/lit-element/lit-element ”net::ERR_ABORTED 404(未找到)。

<head>
    <script src="~/Scripts/my-element.js" type="module"></script>
</head>
<body>
    <my-element></my-element>
</body>

my-element.js我的元素.js

import { LitElement, html } from "../node_modules/lit-element/lit-element";

class MyElement extends LitElement {

    render() {
        return html`
      <!-- template content -->
      <p>A paragraph</p>
    `;
    }
}

customElements.define('my-element', MyElement);

Modify import as修改import

import { LitElement, html } from "lit-element"; import { LitElement, html } from "lit-element";

This can resolve this issue这可以解决这个问题
Import like this像这样导入

import {
  html,
  LitElement,
} from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM