简体   繁体   English

如何使用聚合物3正确定义node_modules的路径

[英]How to properly define a path to node_modules with polymer 3

How should I define an import section inside my WebComponent with polymer 3. 如何使用聚合物3在WebComponent中定义导入部分。

Currenty I have: 目前我有:

import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';

and my catalogs structure looks like: 我的目录结构如下: 目录结构

and I'm getting an error: (index):7 GET http://127.0.0.1:8001/components/ing-dr-plan-details/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js 404 (Not Found) 我收到一个错误:(索引):7 GET http://127.0.0.1:8001/components/ing-dr-plan-details/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js 404(未找到)

Its not 100% clear where you've placed your polymer config, but I assume you have everything within the folder my-web-component. 尚不清楚您将聚合物配置放置在何处,但是我认为您已将所有内容都放在文件夹my-web-component中。 Ie also your node modules should be within that folder see also doc . 也就是说,您的节点模块也应位于该文件夹中, 另请参阅doc

The import code you have 您拥有的导入代码

import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';

and the error does not relate to each other, the terminal is complaining about the missing @webcomponentsjs package. 并且该错误彼此无关,终端抱怨缺少@webcomponentsjs软件包。

This is due to the fact that in Polymer 3, @webcomponentsjs package is not included by default in dependencies anymore (it used to be in Polymer 2). 这是由于以下事实:在Polymer 3中, @webcomponentsjs包在默认情况下不再包含在dependencies (它以前在Polymer 2中)。 You need to manually install @webcomponentsjs with: 您需要使用以下命令手动安装@webcomponentsjs

npm install @webcomponentsjs

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

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