create-react-app
create-react-app copied to clipboard
Uncaught ReferenceError: process is not defined

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
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
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.
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.
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?