create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Uncaught ReferenceError: process is not defined

Open ehsan-esfahani76 opened this issue 3 years ago • 4 comments
trafficstars

Screenshot (2)

ehsan-esfahani76 avatar May 08 '22 06:05 ehsan-esfahani76

I had the same problem when setuping environment variables like in this doc. In production everything works fine but in development mode it says that error.

On the subject there is also this SO answer: https://stackoverflow.com/questions/70368760/react-uncaught-referenceerror-process-is-not-defined None of the answers worked for me

topkat avatar May 18 '22 16:05 topkat

this could be due upgrading to webpack 5 under the hood

if you do any checking on process like

if (process && process.env && process.env.NODE_ENV === 'development')

it no longer knows how to convert it

if you try using it directly

if (process.env.NODE_ENV === 'development')

it may work just a guess with very little information on how you're using it

814k31 avatar May 25 '22 06:05 814k31

I'm having problems when trying to use the npm module microphone-stream that uses the process and Buffer to record audio. I've created my project with npx create-react-app. Unfortunately I just that specific module for my project.

AuboIoT avatar Jul 26 '22 18:07 AuboIoT

this could be due upgrading to webpack 5 under the hood

if you do any checking on process like

if (process && process.env && process.env.NODE_ENV === 'development')

it no longer knows how to convert it

if you try using it directly

if (process.env.NODE_ENV === 'development')

it may work just a guess with very little information on how you're using it

Thanks for this @814k31 ! Was working with someone else's code and couldn't figure this out even after upgrading to react-scripts 5 but this did the trick.

Went from:

const someVal = process?.env?.REACT_APP_SOME_VARIABLE;

To:

const someVal = process.env.REACT_APP_SOME_VARIABLE;

It's back to working again.

Yusuf-Ismail-Homage avatar Oct 18 '22 14:10 Yusuf-Ismail-Homage

This worked for me as well using CRA 5.0.1 but I just don't understand how... How does process.env.REACT_APP_SOME_VARIABLE work where process?.env?.REACT_APP_SOME_VARIABLE does not?

nab911 avatar Dec 20 '22 21:12 nab911