admin管理员组文章数量:1416074
I am trying to follow these instructions for using web ponents. I installed the polymer paper-button with npm install --save @polymer/paper-button
, addded the below to my index.html and opened it with vscode's live-server. But I get a console error saying: Uncaught TypeError: Failed to resolve module specifier "@polymer/iron-flex-layout/iron-flex-layout.js". Relative references must start with either "/", "./", or "../".
. I would like to solve this without using a module bundler like webpack.
<script type="module" src="node_modules/@polymer/paper-button/paper-button.js"></script>
...
<paper-button raised class="indigo">raised</paper-button>
I am trying to follow these instructions for using web ponents. I installed the polymer paper-button with npm install --save @polymer/paper-button
, addded the below to my index.html and opened it with vscode's live-server. But I get a console error saying: Uncaught TypeError: Failed to resolve module specifier "@polymer/iron-flex-layout/iron-flex-layout.js". Relative references must start with either "/", "./", or "../".
. I would like to solve this without using a module bundler like webpack.
<script type="module" src="node_modules/@polymer/paper-button/paper-button.js"></script>
...
<paper-button raised class="indigo">raised</paper-button>
Share
Improve this question
edited Dec 6, 2019 at 18:23
Max888
asked Dec 6, 2019 at 18:11
Max888Max888
3,8505 gold badges35 silver badges76 bronze badges
2 Answers
Reset to default 5A workaround I have found is to instead use https://unpkg./ as per below:
<script type="module" src="https://unpkg./@material/mwc-button@latest/mwc-button.js?module"></script>
Note: you need to add the ?module
parameter to the end of the URL in order for unpkg to fix the bare module syntax within the file requested otherwise it just returns the original file with bare module imports.
The error you're getting refers to the inability of browsers - even those that support ES modules - to resolve bare module imports (import foo from 'bar';
).
Yes, here:
↓
<script type="module" src="node_modules/@polymer/paper-button/paper-button.js"></script>
you're importing by relative path but paper-button
in turn is importing other modules by bare specifier:
paper-button.js:11:1
import '@polymer/iron-flex-layout/iron-flex-layout.js';
To know more about modules in the browser and the reasons behind the lack of support for bare specifiers I would remend this article by Damien Seguin.
You don't necessarily need a module bundler to be able to launch the application: polymer serve
, Polymer's dev server, resolves module specifiers automatically. Also, Polymer CLI's build
mand may be of help if you don't want to manually configure a build system or alternatively tools like Babel can help you transform imports without bundling.
本文标签: javascriptImporting web component without module bundlerStack Overflow
版权声明:本文标题:javascript - Importing web component without module bundler - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745245958a2649557.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论