Error using an importmap: "Error while transforming file. See the terminal for more information."

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

Error using an importmap: "Error while transforming file. See the terminal for more information."

问题

以下是您要翻译的内容:

I am experimenting with script type="importmap" and have an issue that I am sure has a simple answer.

This works:

<html>
    <head>
       ....
        <script type="module">
            import './webcomponents/lit-test.js';
        </script>
    </head>

    <body>
        <lit-test></lit-test>
    </body>
</html>

This doesn't:

<html>
    <head>
       ....
        <script type="importmap">
            {
                "imports": {
                    "lit-test": "./webcomponents/lit-test.js"
                }
            }
        </script>
        <script type="module">
            import 'lit-test';
        </script>
    </head>

    <body>
        <lit-test></lit-test>
    </body>
</html>

The error in the browser:

Error while transforming file. See the terminal for more information.

The error in the console:

GET http://localhost:8000/ 500 (Internal Server Error)

Can anyone explain what is incorrect?

lit-test.js

import { css, html, LitElement } from 'lit';

class Lit_test extends LitElement {
    render() {
        return html` Hello `;
    }
}
customElements.define('lit-test', Lit_test);

The terminal:

Error using an importmap: "Error while transforming file. See the terminal for more information."

File structure:

Error using an importmap: "Error while transforming file. See the terminal for more information."

英文:

I am experimenting with script type="importmap" and have an issue that I am sure has a simple answer.

This works:

&lt;html&gt;
    &lt;head&gt;
       ....
        &lt;script type=&quot;module&quot;&gt;
            import &#39;./webcomponents/lit-test.js&#39;;
        &lt;/script&gt;
    &lt;/head&gt;

    &lt;body&gt;
        &lt;lit-test&gt;&lt;/lit-test&gt;
    &lt;/body&gt;
&lt;/html&gt;

This doesn't:

&lt;html&gt;
    &lt;head&gt;
       ....
        &lt;script type=&quot;importmap&quot;&gt;
            {
                &quot;imports&quot;: {
                    &quot;lit-test&quot;: &quot;./webcomponents/lit-test.js&quot;
                }
            }
        &lt;/script&gt;
        &lt;script type=&quot;module&quot;&gt;
            import &#39;lit-test&#39;;
        &lt;/script&gt;
    &lt;/head&gt;

    &lt;body&gt;
        &lt;lit-test&gt;&lt;/lit-test&gt;
    &lt;/body&gt;
&lt;/html&gt;

The error in the browser:

> Error while transforming file. See the terminal for more information.

The error in the console:

> GET http://localhost:8000/ 500 (Internal Server Error)

Can anyone explain what is incorrect?

lit-test.js

import { css, html, LitElement } from &#39;lit&#39;;

class Lit_test extends LitElement {
	render() {
		return html` Hello `;
	}
}
customElements.define(&#39;lit-test&#39;, Lit_test);

The terminal:

Error using an importmap: "Error while transforming file. See the terminal for more information."

File structure:

Error using an importmap: "Error while transforming file. See the terminal for more information."

答案1

得分: 1

你可能需要安装 @web/dev-server-import-maps 插件,如果你正在使用开发服务器。

安装包:

npm i --save-dev @web/dev-server-import-maps

将插件添加到你的 web-dev-server.config.mjsweb-test-runner.config.js 文件中:

import { importMapsPlugin } from '@web/dev-server-import-maps';

export default {
  plugins: [importMapsPlugin()],
};

更多信息

英文:

You might need to install @web/dev-server-import-maps plugin if you are using development server.

Install the package:

npm i --save-dev @web/dev-server-import-maps

Add the plugin to your web-dev-server.config.mjs or web-test-runner.config.js:

import { importMapsPlugin } from &#39;@web/dev-server-import-maps&#39;;

export default {
  plugins: [importMapsPlugin()],
};

For More Information

huangapple
  • 本文由 发表于 2023年8月4日 01:09:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76830251.html
匿名

发表评论

匿名网友

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

确定