Uncaught ReferenceError: process is not defined

The ` Uncaught ReferenceError: process is not defined` occurs when trying to access the process variable in an environment where it is not defined.

This happens in a Vite/React project when trying to access an environment variable in the .env file similar to the following:

some_env_key = some_env_value

Then you try accessing the env value with the code below:

const definedVariable = proces.env.some_env_key

How to solve error in a Vite/React project

Vite development server takes a different approach to handling environment variables. It utilizes the import.meta.vite object

Add the environment variables to the .env file with a prefix of Vite similar to the code below:

VITE_some_env=some_env_value

Expose the value of the variable using an `import.meta.env` object as shown below

const definedVariable = import.meta.env.VITE_some_env

References

0
Subscribe to my newsletter

Read articles from Oluwatomisin Bello directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Oluwatomisin Bello
Oluwatomisin Bello

I am constantly looking for a way to create magic with code.