isNodeJS breaks on Electron 'main' process which really IS NodeJS
See original GitHub issuethe 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:
const isNodeJS =
typeof process === "object" &&
process + "" === "[object process]" &&
!process.versions["nw"] &&
!process.versions["electron"];
… 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:
- Web browser and its version: Electron 5.x (n/a)
- Operating system and its version: MacOS Catalina
- PDF.js version: 2.4.456
- Is a browser extension: no
Steps to reproduce the problem:
- Try to use PDF.js from Electron main process
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (2 by maintainers)
Top GitHub Comments
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
typeof window !== "undefined"
check works, then that’s probably preferred here.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.