JS Test NPM dependencies

This feels like a bug but I thought I’d check here to see if I’m doing something wrong.

I have a multiplatform library, it’s meant for the browser but can be run in nodejs with certain npm dependencies, which is useful for unit testing in CI.

In order to emulate the browser’s XMLHttpRequest, I have an npm dependency in jsTest like so:

val jsTest by getting {
	dependencies {
		implementation(kotlin("test", version = kotlinVersion))
		implementation(kotlin("test-js", version = kotlinVersion))
		runtimeOnly(npm("xmlhttprequest", "1.8.0"))
	}
}

This works when testing the library, however when running jsBrowserProductionWebpack from the dependent application, I get errors as if it’s trying to compile in the test dependencies.

ERROR in D:/Projects/..../kotlin/build/js/node_modules/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Error: Can't resolve 'child_process' in 'D:\Projects\....\kotlin\build\js\node_modules\xmlhttprequest\lib'
 @ D:/Project/..../kotlin/build/js/node_modules/xmlhttprequest/lib/XMLHttpRequest.js 15:12-36
 @ ./kotlin-dce/acornui-acornui-utils.js
 @ ./kotlin-dce/mpweb-app.js
 @ multi ./kotlin-dce/mpweb-app.js

And for reference, I’m using mocha:

js { browser.testTask { useMocha() } }

And this is kotlin version 1.3.70-eap-42

Another strange thing is that this error doesn’t always happen, if I “jiggle” it enough it will compile.

So I guess my question is - 1) Is there a more correct way to do this? 2) Is there a workaround?