Open emerikool opened 3 years ago
@emerikool Perhaps typeof process != "undefined" && process.browser
? Should be careful and test with all the different types of electron first though! (Context isolation=true, nodeIntegration=false, etc)
What do you mean by process.browser ? We use mochapack that bundle with webpack and run mocha + jsdom. In our case process.browser is undefined, perhaps best approach is to add a custom property to process object to force detection ?
@emerikool you can check: process.platform=undefined OR process.browser (both seem used?)
process.platform is defined (win32) and process.browser is undefined
@emerikool Seems like something you should figure out with the mochapack people maybe? process
definitely isn't polyfilled by default...
I don't think it's related to mochapack, same issue should occur with webpack and any emulated browser.
In case of emulated browser, dartNodeIsActuallyNode
needs to be overriden like electron:
https://github.com/mbullington/node_preamble.dart/blob/20c5bee0bbe6fefead1509bbdbbac06072b778e2/lib/preamble.js#L50
by replacing process.versions.hasOwnProperty('electron')
with something matching this particular case.
I did not find a valid property in process object to fit this use case that's why I suggest to add a custom one like:
if ("undefined" !== typeof process && process.hasOwnProperty('forceNode') && process.versions && process.versions.hasOwnProperty('node')) {
Having encountered this problem, my current workaround is set process.versions.electron = ''
to force dartNodeIsActuallyNode = true
We are facing an issue on dart sass due to environement detection. With jsdom environment is not detected as a Node one and imports are not resolved.
Jsdom emulate a web browser by adding a window object that makes failed node detection: https://github.com/mbullington/node_preamble.dart/blob/20c5bee0bbe6fefead1509bbdbbac06072b778e2/lib/preamble.js#L41