DEV Community

Vidip Ghosh
Vidip Ghosh

Posted on

Using .env in React + Vite

I was using .env in my react app created using vite. I have a token which needs to be hidden.

As soon as I wrote process.env.AUTH_KEY, I got the following error:
Image description

Then on searching I came across the right way of using .env variables in React + Vite project.

**
.jsx

const READ_KEY = import.meta.env.VITE_GH_AUTH_KEY;
const octokit = new Octokit({ auth: READ_KEY });
Enter fullscreen mode Exit fullscreen mode

**

**
.env
VITE_GH_AUTH_KEY = 'your-auth-token'
**

For reference, please refer the article: https://stackoverflow.com/questions/72628089/error-in-vite-preview-uncaught-in-promise-referenceerror-process-is-not-def

Top comments (0)