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.

ReferenceError: process is not defined

See original GitHub issue

When trying to export an html node to image, I get the following erorr:

Error: Uncaught (in promise): ReferenceError: process is not defined
ReferenceError: process is not defined

Expected Behavior

I should get the node as a image

Current Behavior

Error

Possible Solution

The error is in the getPixelRatio function:

const val = process && process.env ? process.env.devicePixelRatio : null

This may be fixed with a try catch like this:

let _process;
try {
   _process = process;
} catch(){
}

const val = _process && _process.env ? _process.env.devicePixelRatio : null

Steps To Reproduce

Error Message & Stack Trace

Error: Uncaught (in promise): ReferenceError: process is not defined
ReferenceError: process is not defined
    at getPixelRatio (util.js:99)
    at index.js:40
    at ZoneDelegate.invoke (zone-evergreen.js:364)
    at Zone.run (zone-evergreen.js:123)
    at zone-evergreen.js:857
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Zone.runTask (zone-evergreen.js:167)
    at drainMicroTaskQueue (zone-evergreen.js:569)
    at invokeTask (zone-evergreen.js:484)
    at ZoneTask.invoke (zone-evergreen.js:469)
    at resolvePromise (zone-evergreen.js:798)
    at zone-evergreen.js:705
    at rejected (tslib.es6.js:72)
    at ZoneDelegate.invoke (zone-evergreen.js:364)
    at Object.onInvoke (core.js:28237)
    at ZoneDelegate.invoke (zone-evergreen.js:363)
    at Zone.run (zone-evergreen.js:123)
    at zone-evergreen.js:857
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Object.onInvokeTask (core.js:28225)

Additional Context

Your Environment

  • html-to-image: 1.3.20
  • OS: Windows 10
  • Browser: Chrome 87

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
linjie997commented, Dec 2, 2020

@najmulansari while your fix can work, it’s a workaround and a fix/check should be made in the library and not by the client using it.

2reactions
najmulansaricommented, Dec 1, 2020

@injie997 I fixed this by adding below code in index.html page.

`

<script> var global = global || window; var Buffer = Buffer || []; var process = process || { env: { DEBUG: undefined }, version: [] }; </script>`
Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: “process is not defined” - GIMTEC
In this case, process is not defined in the browser environment, hence the error. The solution is to remove the reference to process...
Read more >
javascript - Uncaught ReferenceError: process is not defined
I am using the command "npm start" which refers to the "start" script inside package.json that is set to "start": "http-server -a localhost...
Read more >
"Uncaught ReferenceError: process is not defined" and the ...
The Uncaught ReferenceError: process is not defined happens when when a non-existent (here: process) variable is referenced .
Read more >
process is not defined (NOT react-error-overlay ... - GitHub
Using the optional chaining operator with process ( process?.env ) throws a ReferenceError stating that process is not defined.
Read more >
Uncaught ReferenceError: process is not defined
The error Uncaught ReferenceError: process is not defined may happen when the code tries to get access to the process object that provides ......
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