question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

isNodeJS breaks on Electron 'main' process which really IS NodeJS

See original GitHub issue

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:

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:

  1. Try to use PDF.js from Electron main process

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Snuffleupaguscommented, Apr 8, 2020

Any objection to a PR with this? It’s a little functiony but it’s clear and easy to read.

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.

0reactions
ava-cassiopeiacommented, Jan 18, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Process | Node.js v19.3.0 Documentation
Normally, the Node.js process will exit when there is no work scheduled, but a listener registered on the 'beforeExit' event can make asynchronous...
Read more >
Why the Hell Would I Use Node.js? A Case-by-case Tutorial
While you may run background processes on the main server, this approach may not scale well once the load increases. You may distribute...
Read more >
Process is not defined for Electron's Getting Started App
A new major Electron version has been released which broke the tutorial. The specific breaking change is a new default value of ...
Read more >
What is Node.js and how does it differ from a browser - Medium
js. Whether it is directly required as a server solution or if it's required as a supporting tool for your web development it...
Read more >
Electron is Amazing - The Blinking Caret
It turns out that Electron is Node.js packaged together with ... The main process is the process in electron where you have access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found