Fengari fails loading on web environment with process global variable present
nbarrera opened this issue · 2 comments
Hi, I 'm using fengari on a medium sized project where also some other libs are being used.
I was using a pre-npm version of fengari where a global var WEB should be present for fengari to assume it was a browser env.
I saw that now you are detecting by means of typeof process which sounds fine, but I got a problem with that in my project.
I got this process lib as a transitive dependency which is defining the process global variable, and in case it's a web environment it defines process.web as true.
So the way fengari detects web/node is failing for me now, I 'm in web but it assumes is NodeJS because process exists although it is not the NodeJS process object.
Do you think fengari could check for the existence of that process.web (that process lib seems like widely used).
If not, is there any chance to add back the WEB global variable as a way to force fengari into web mode even if process is defined?
PS: I 've already tried by using de webpack DefinePlugin and add typeof process as "undefined" but same thing happend though.
Hope you could consider any solution to this problem, I 'm happy to create a PR with the suggested approach.
Thanks in advance
I could add the suggestion to switch the way NodeJS is detected:
try {
Object.prototype.toString.call(global.process) === '[object process]'
// it is nodejs
} catch () {
// is not nodejs
}
I took that from:
https://github.com/iliakan/detect-node
in that case even if the process variable exists, it will only detect as if in NodeJS when in fact it is in NodeJS.
By looking at the comments on another Issue I understood that at the current version of fengari I must use fengari-web to avoid that kind of problem.
So there is no need for modification when using it like that.
I thought I didn't need fengari-web as I won't use the webpack loader nor script includes, but then I realized that fengari-web was also exporting what I needed from fengari and fengari-interop.