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.

Uncaught ReferenceError: process is not defined (NOT react-error-overlay)

See original GitHub issue

Describe the bug

Using the optional chaining operator with process (process?.env) throws a ReferenceError stating that process is not defined.

I originally encountered this behaviour because a dependency is using that syntax, then I tried to write the same in my code and it still breaks.

Note that process.env works, and it doesn’t appear to be a problem with react-error-overlay (I also tried to use this fix without success).

A workaround is to add the following in index.tsx:

if (!('process' in window)) {
  // @ts-ignore
  window.process = {}
}

Did you try recovering your dependencies?

I just freshly installed it from scratch using

yarn create react-app temp-app --template typescript

Which terms did you search for in User Guide?

https://github.com/facebook/create-react-app/issues?q=is%3Aissue+uncaught+referenceError%3A+process+is+not+defined https://github.com/facebook/create-react-app/issues?q=is%3Aissue+process+is+not+defined

Environment

Environment Info:

  current version of create-react-app: 5.0.0
  running from ~/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

  System:
    OS: macOS 12.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 16.12.0 - ~/.nvm/versions/node/v16.12.0/bin/node
    Yarn: 1.22.15 - ~/.nvm/versions/node/v16.12.0/bin/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v16.12.0/bin/npm
  Browsers:
    Chrome: 99.0.4844.83
    Edge: Not Found
    Firefox: Not Found
    Safari: 15.3
  npmPackages:
    react: ^17.0.2 => 17.0.2 
    react-dom: ^17.0.2 => 17.0.2 
    react-scripts: 5.0.0 => 5.0.0 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. Install CRA yarn create react-app temp-app --template typescript
  2. Add {process?.env?.NODE_ENV} in App.tsx (e.g. in the <p>)

Expected behavior

development is shown

Actual behavior

blank page, the following error in the browser console Screenshot 2022-03-28 at 09 39 42

Reproducible demo

https://github.com/EnoahNetzach/create-react-app-no-process

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
lovetingyuancommented, Sep 11, 2022

this is so stupid… can not believe react team could make such mistake…

6reactions
wayneblosscommented, Apr 15, 2022

It doesn’t matter if you destructure or use optional chaining, this error just happens whenever you access process outside of a React component as far as I can see.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Uncaught ReferenceError: process is not defined
The error is as a result of react-error-overlay (which many people would never have heard of because it is a dependency of react-scripts...
Read more >
Resolving Create React App's “Uncaught ReferenceError
A recent change to Create React App, or more specifically react-scripts , has caused hot reloading to throw an error: Uncaught ...
Read more >
process is not defined , while the Ui freezes on using D2 react ...
Uncaught ReferenceError : process is not defined , while the Ui freezes ... react-script into v5.0.0; We install react-error-overlay v6.0.9 ...
Read more >
React Uncaught ReferenceError: process is not defined-Reactjs
The problem is because you lose window.process variable when React hotloads, and process exists only on node, not the browser. So you should...
Read more >
process is not defined in React UIKit v3 - Sendbird Community
Uncaught ReferenceError : process is not defined in React UIKit v3 ... The v3 import has been changed. Please do the migration and...
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