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).
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:
ReferenceError: window is not defined?