Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack and jsdom detection issue #26

Open
emerikool opened this issue Apr 8, 2021 · 7 comments
Open

Webpack and jsdom detection issue #26

emerikool opened this issue Apr 8, 2021 · 7 comments

Comments

@emerikool
Copy link

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:

var dartNodeIsActuallyNode = !dartNodePreambleSelf.window

@Mstrodl
Copy link
Collaborator

Mstrodl commented Apr 8, 2021

@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)

@emerikool
Copy link
Author

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 ?

@Mstrodl
Copy link
Collaborator

Mstrodl commented Apr 9, 2021

@emerikool you can check: process.platform=undefined OR process.browser (both seem used?)

@emerikool
Copy link
Author

process.platform is defined (win32) and process.browser is undefined

@Mstrodl
Copy link
Collaborator

Mstrodl commented Apr 9, 2021

@emerikool Seems like something you should figure out with the mochapack people maybe? process definitely isn't polyfilled by default...

@emerikool
Copy link
Author

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:

if ("undefined" !== typeof process && process.versions && process.versions.hasOwnProperty('electron') && process.versions.hasOwnProperty('node')) {

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')) {

@fangbinwei
Copy link

Having encountered this problem, my current workaround is set process.versions.electron = '' to force dartNodeIsActuallyNode = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants