Environment Variables Not Working with SWR

I’m finding it hard to use ENV variables with the SWR hook for data fetching.

I’ve been using it this way:

const videoURLWithEnv = `https://youtube.googleapis.com/youtube/v3/search?part=snippet&channelId=UCwkj9jcrMZCcbcIa6nF5LNQ&maxResults=3&order=date&key=${process.env.GOOGLE_API_KEY}`;

When I dont put my API key in the ENV file, it works like magic.

I’ve tried to implement the best practices of ENV files like not surrounding the varibale value with quotes, but it’s still not working.

While thinking it could be due to the YouTube API or the Google API key, I fetched data with another API but the problem remains the same — SWR still didn’t read the ENV variable.