首页 > 解决方案 > Polymer 3 build - 尝试访问 mixin 时浏览器中的捆绑错误

问题描述

我有一个可以正常工作的 Polymer 3 应用程序。但是,如果我构建并捆绑它,我会在捆绑时遇到问题。我现在只做es6。我什至不知道如何解决这个问题......非常卡住。

聚合物.json

  "builds": [
    {
      "name": "es6-bundled",
      "browserCapabilities": [
        "es2015"
      ],
      "js": {
        "minify": false,
        "transformModulesToAmd": true
      },
      "css": {
        "minify": false
      },
      "html": {
        "minify": false
      },
      "bundle": true,
      "addServiceWorker": false
    }
  ],

浏览器错误:

all-items:formatted:211 Uncaught TypeError: (0 , _mainApp.PauseForRipple) is not a function
    at user-login.js? [sm]:4

捆绑包中的代码:

define(["../main-app.js"], function(_mainApp) {
    "use strict";

    class UserLogin extends (0,
    _mainApp.PauseForRipple)(_mainApp.PolymerElement) {
        static get template() {
            return _mainApp.html`
      <style>
        :host {
          display: flex;
          align-items: center;

构建前的原始代码:

import { PauseForRipple } from '../mixins/pause-for-ripple-mixin.js';

class UserLogin extends PauseForRipple(PolymerElement) {
  static get template() {
    return html`
      <style>
        :host {
          display: flex;
          align-items: center;
          justify-content: center;

标签: polymerpolymer-3.xpolymer-cli

解决方案


根本原因是我有双重导入导入'./login/user-login.js'; 在 main-app.js 中。


推荐阅读