keeweb/kdbxweb

window is not defined - running under NodeJS

Closed this issue · 3 comments

Hi! We use your library over at Buttercup, and we're upgrading kdbxweb. It seems we've encountered an issue where the current copy of this library references window:

/*! kdbxweb v1.5.2, (c) 2019 Antelle, opensource.org/licenses/MIT */
(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("crypto"), require("xmldom"));
	else if(typeof define === 'function' && define.amd)
		define(["crypto", "xmldom"], factory);
	else if(typeof exports === 'object')
		exports["kdbxweb"] = factory(require("crypto"), require("xmldom"));
	else
		root["kdbxweb"] = factory(root["crypto"], root["xmldom"]);
})(window, function(__WEBPACK_EXTERNAL_MODULE__42__, __WEBPACK_EXTERNAL_MODULE__44__) {
return /******/ (function(modules) { // webpackBootstrap

Which is of course undefined:

ReferenceError: window is not defined
    at eval (webpack:///./node_modules/kdbxweb/dist/kdbxweb.js?:4:4)
    at Object../node_modules/kdbxweb/dist/kdbxweb.js (/Users/pez/git/buttercup-importer/dist/buttercup-importer.js:2311:1)
    at __webpack_require__ (/Users/pez/git/buttercup-importer/dist/buttercup-importer.js:21:30)
    at eval (webpack:///./source/importers/KDBXImporter.js?:2:15)

This only cropped up after updating from 1.2.7 to 1.5.2. I'm using Node v10 at the moment.

Ok, I fixed the issue myself as I'm using Webpack to bundle for node+browser - Using imports-loader I simply do: const KDBXWeb = require("imports-loader?window=>this!kdbxweb");

This of course doesn't fix it on Node, but only if you bundle this library further.

Fixed this, it should work well in 1.5.3.

This.. is probably the fastest response and fix I've ever seen. Amazing @antelle!