Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
dynamic commonJS module loading with parcel

I have as part of my application

"use strict";

exports.makeNodeCompatible = function() {
  if (typeof(DOMParser) === 'undefined') {
    (function(global) {
      var jsdom = require('jsdom'),
          dom = new jsdom.JSDOM('');

      global.DOMParser = dom.window.DOMParser;
    })(global);
  }
};

The purpose of making the code like this is that it would work both in node and in the browser. I like to keep this code being compatible with both environments (please consider this in answer).

  • Source for inspiration: https://github.com/jkutianski/d3-templating/blob/29366e4c9dda7b044eb12ee325e8ee99b9f26ced/src/template.js#L3-L10 (this is not my code, just where i found this !)
  • Source for recommendation jsdom: https://stackoverflow.com/a/55668667/1833322

When i run my app directly from unbundled sources node index.js --help everything works well. When i bundle with parcel first i get an error ReferenceError: window is not defined. I went into dist/index.js (the bundled file) and manually found my application code and moved it to the end of this file. After that the dist version worked. This indicates to me that parcel didn't put the code of my app and the jsdom in the right order.

Question:

  • Can i either rewrite this code somehow so that parcel can pick up on the order of dependency? (and still keep browser compatibility)
  • Can i manually tell parcel about the order of dependency in some configuration?
  • Maybe my findings are incorrect and there is a different cause for ReferenceError: window is not defined?
  • If parcel does not support this is there an alternative bundler that i can try?
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda