-
Notifications
You must be signed in to change notification settings - Fork 10.3k
isNodeJS breaks on Electron 'main' process which really IS NodeJS #11790
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
Comments
Any objection to a PR with this? It's a little functiony but it's clear and easy to read. function computeElectronProcessType() {
if (process && process.versions && process.versions["electron"]) {
if (typeof window !== "undefined") {
return "renderer";
}
return "main";
}
return "none";
}
const electronProcessType = computeElectronProcessType();
// NW.js / Electron is a browser context, but copies some Node.js objects; see
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
// https://electronjs.org/docs/api/process#processversionselectron
const isNodeJS =
typeof process === "object" &&
process + "" === "[object process]" &&
!process.versions["nw"] &&
electronProcessType !== "renderer";
export { isNodeJS }; |
... and I don't have a fix for NW |
Well, it seems very unfortunate to add dependencies on what essentially looks like internal Electron-state to the PDF.js code-base. If something simple like e.g. an inline |
@Snuffleupagus internal Electron state? It's just a check to see if the window was there. I'm not calling any electron functions. I just moved this to a function so it was a big more readable / maintainable. It's not dependent on any electron state. |
Based on the above, I don't think it should be entirely surprising if someone unfamiliar with Electron would assume that the quoted names refer to some kind of "internal" Electron state.
Again, then please just add a simple
By introducing a bunch of (what appears to be) arbitrary strings, i.e. "renderer"/"main"/"none", that would actually make the code much more difficult to read/maintain since anyone looking at it wouldn't really know what they are meant to represent. |
I would agree with the above. If a simple |
FWIW, I think I'm running into a similar issue. When upgrading from |
Fixed by PR #12085, perhaps? |
Yes, this should be fixed now. |
I use pdf-parse module instead of pdfjs in main process to parse metainfo of PDF document. |
I'm not sure if I should open a new bug or comment on this one, but I'm still experiencing this exact same issue using Electron 11.2.0 and pdfjs-dist 2.5.207. When I open up If it's relevant, my
|
Ah, I commented too soon. A quick search for 12085 (this fixing PR's ID) on https://github.com/mozilla/pdf.js/releases reveals that the fix rolls up into v2.6.347, which is currently a pre-release. Please excuse the noise, I'll figure out how to integrate that version into my build. |
the isNodeJS code is broken on Electron in the 'main' process.
The problem is that in Electron there are two processes. The 'main' and the 'renderer' ... the 'main's is really just node. The 'renderer' is sort of a browser with some 'require' semantics.
I assume this code was added to work within the renderer process but it accidentally broke the 'main' process.
Here's the code in question:
is_node.js:
... I think this can be fixed by just adding another check to:
typeof window !== 'undefined'
... when process.versions["electron"]...it might be best to have a cleaner function that has 'electron_process_type' of 'none' , 'renderer' or 'main'
... I'm can submit a PR for this later once I verify a fix...
Attach (recommended) or Link to PDF file here: n/a ... breaks on all of them.
Configuration:
Steps to reproduce the problem:
The text was updated successfully, but these errors were encountered: