es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

La salida del complemento Rollup “rollup-plugin-polyfills-loader” da un error.

Tengo el siguiente rollup.config.js (solo he pegado la información relevante para este problema):

import html from '@web/rollup-plugin-html';
import polyfillsLoader from '@web/rollup-plugin-polyfills-loader';
const htmlPlugin = html({
  inputPath: 'index.html',
  inject: false,
});
polyfillsLoader({
  modernOutput: {
    name: 'modern',
  },
  // Detección de características para cargar paquetes antiguos
  legacyOutput: {name: 'legacy', test: '!(\'noModule\' in HTMLScriptElement.prototype)'},

  // Lista de polyfills a inyectar (cada uno tiene detección de características individual)
  polyfills: {
    hash: true,
    coreJs: true,
    regeneratorRuntime: true,
    fetch: true,
    webcomponents: true,
    // Configuración personalizada para cargar el módulo de soporte de polyfill de Lit,
    // necesario para el interfaz con los polyfills de webcomponents
    custom: [
      {
        name: 'lit-polyfill-support',
        path: 'node_modules/lit/polyfill-support.js',
        test: '!(\'attachShadow\' in Element.prototype)',
        module: false,
      },
    ],
  },
}),

Esto en realidad inyecta el siguiente script en mi construcción:

<script>(function () {
  function polyfillsLoader() {
    function loadScript(src, type, attributes = []) {
      return new Promise(function (resolve) {
        var script = document.createElement('script');

        function onLoaded() {
          if (script.parentElement) {
            script.parentElement.removeChild(script);
          }

          resolve();
        }

        script.src = src;
        script.onload = onLoaded;
        attributes.forEach(att => {
          script.setAttribute(att.name, att.value);
        });

        script.onerror = function () {
          console.error('[polyfills-loader] failed to load: ' + src + ' check the network tab for HTTP status.');
          onLoaded();
        };

        if (type) script.type = type;
        document.head.appendChild(script);
      });
    }

    var polyfills = [];

    if (!('noModule' in HTMLScriptElement.prototype)) {
      polyfills.push(loadScript('./polyfills/regenerator-runtime.de2e6a3a74a500cae72a3cab1a403efc.js'));
    }

    if (!('fetch' in window)) {
      polyfills.push(loadScript('./polyfills/fetch.a1ad5fb96dc0cb61b9454244c9bd7fe6.js'));
    }

    if (!('attachShadow' in Element.prototype) || !('getRootNode' in Element.prototype) || window.ShadyDOM && window.ShadyDOM.force) {
      polyfills.push(loadScript('./polyfills/webcomponents.d7ffce1754011cfedff5f846f12e0c11.js'));
    }

    if (!('noModule' in HTMLScriptElement.prototype) && 'getRootNode' in Element.prototype) {
      polyfills.push(loadScript('./polyfills/custom-elements-es5-adapter.3342b468203af1a14ca005e80d14148f.js'));
    }

    if (!('attachShadow' in Element.prototype)) {
      polyfills.push(loadScript('./polyfills/lit-polyfill-support.82aa27f27be323af5a455ac87919622a.js'));
    }

    function loadFiles() {
      if (!('noModule' in HTMLScriptElement.prototype)) {
        [function () {
          return loadScript('./legacy-my-header-d84233c1.js', 'module', []);
        }, function () {
          return loadScript('./legacy-my-footer-353e3024.js', 'module', []);
        }, function () {
          return loadScript('./legacy-my-breadcrumbs-6977da2c.js', 'module', []);
        }, function () {
          return loadScript('./legacy-my-anchor-menu-3a71e855.js', 'module', []);
        }, function () {
          return loadScript('./legacy-my-contact-box-605983a9.js', 'module', []);
        }, function () {
          return loadScript('./legacy-my-transition-96158dc5.js', 'module', []);
        }, function () {
          return loadScript('./legacy-my-animated-slot-d7901404.js', 'module', []);
        }].reduce(function (a, c) {
          return a.then(c);
        }, Promise.resolve());
      } else {
        [function () {
          return loadScript('./my-header-df4bd84c.js', 'module', []);
        }, function () {
          return loadScript('./my-footer-2e03a59d.js', 'module', []);
        }, function () {
          return loadScript('./my-breadcrumbs-ebb2c4c1.js', 'module', []);
        }, function () {
          return loadScript('./my-anchor-menu-9f6da4d8.js', 'module', []);
        }, function () {
          return loadScript('./my-contact-box-77b64be7.js', 'module', []);
        }, function () {
          return loadScript('./my-transition-b8f34c3f.js', 'module', []);
        }, function () {
          return loadScript('./my-animated-slot-7cfd347d.js', 'module', []);
        }].reduce(function (a, c) {
          return a.then(c);
        }, Promise.resolve());
      }
    }

    if (polyfills.length) {
      Promise.all(polyfills).then(loadFiles);
    } else {
      loadFiles();
    }
  }

  if (!('noModule' in HTMLScriptElement.prototype)) {
    var s = document.createElement('script');

    function onLoaded() {
      document.head.removeChild(s);
      polyfillsLoader();
    }

    s.src = "./polyfills/core-js.26813355b620c9d0fe88992b4621ff45.js";
    s.onload = onLoaded;

    s.onerror = function () {
      console.error('[polyfills-loader] failed to load: ' + s.src + ' check the network tab for HTTP status.');
      onLoaded();
    };

    document.head.appendChild(s);
  } else {
    polyfillsLoader();
  }
})();</script>

Esto me da un error:

Se esperaba ‘)’

¿Qué he hecho mal?

Tags:  , ,

Answer

  1. Avatar for davy.ai

    Es difícil determinar exactamente qué está causando el error sin ver el contexto y el código completo. Sin embargo, basándose en el código pegado, parece que puede faltar algún paréntesis de cierre en algún lugar del código. El mensaje de error indica que se estaba esperando un paréntesis de cierre, lo que podría indicar que no se cerró correctamente en algún lugar anterior del código. Puede ser útil revisar cuidadosamente el código y buscar cualquier paréntesis faltante o mal colocado.

Comments are closed.