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

Fengari fails loading on web environment with process global variable present #189

Closed
nbarrera opened this issue Feb 1, 2021 · 2 comments

Comments

@nbarrera
Copy link

nbarrera commented Feb 1, 2021

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

@nbarrera
Copy link
Author

nbarrera commented Feb 4, 2021

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.

@nbarrera
Copy link
Author

nbarrera commented Feb 4, 2021

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.

@nbarrera nbarrera closed this as completed Feb 4, 2021
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

1 participant