Having trouble retrieving .env variables in NextJS GraphQL setup

After trying all the suggested solutions on Stack Overflow and researching through previous questions, I have come here seeking help. I am using the latest version of NextJS (version 14) and encountering an issue with integrating GraphQL Apollo client into my application.

The main problem lies in dynamically changing the URI of the Apollo client based on the environment variable (NODE_ENV) set in the .env file. However, when I console.log(process.env), it returns an empty object in the browser console while displaying the expected values in my VS Code's console.

You can view my .env and .env.local files for reference:

https://i.stack.imgur.com/X1H3Z.png

Below is the code snippet for my Apollo Client:

import { ApolloClient, InMemoryCache } from "@apollo/client";

const CreateApolloClient = () => {
  console.log(process.env, "PROCESS");
  return new ApolloClient({
    uri: `http://localhost:4000/graphql`,
    cache: new InMemoryCache(),
  });
};

export default CreateApolloClient;

I would appreciate any assistance or suggestions to resolve this issue. Please feel free to ask for more details if needed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to resolve 500 error on Vercel in Next.js despite successful local development

Here is the content of route.ts import fs from 'fs'; import path from 'path'; import PizZip from 'pizzip'; import Docxtemplater from 'docxtemplater'; import { NextRequest, NextResponse } from 'next/server'; ...

What is the best way to assign a flash variable in Next.js prior to redirecting?

While Laravel in PHP has a straightforward way of handling flash data with https://laravel.com/docs/9.x/session#flash-data, I assumed Next.js would have a similar approach. I expected to be able to achieve something like the following: export const getSer ...

`There seems to be an unusual issue causing tailwindcss to malfunction`

It seems like my tailwindcss isn't functioning properly. Is there something I missed? tailwind.config.js /** @type {import('tailwindcss').Config} */ module.exports = { content: [ "./app/**/*.{js,ts,jsx,tsx,mdx}", ". ...

Reinitializing the database with Cypress (postgresql)

When populating the database, I intentionally do it partially for certain tests. However, after completing all tests, I would like to reset the database in order to avoid any complications that may arise during the next populate process. How can I efficien ...

Experiencing compatibility issues with NextAuth and Prisma on Netlify when using NextJS 14

While the website is functioning correctly on development and production modes, I am encountering issues when testing it on my local machine. After deploying to Netlify, the website fails to work as expected. [There are errors being displayed in the conso ...

The provided property `verseObj.version_id` is not valid. It should be of type `object`, but a `string` value has been supplied

I am currently developing a unique and innovative public prayer journal that allows for the addition of verses in full stack. Surprisingly, I encountered an error when rendering the form which was not present a few days ago. Strangely enough, I have made n ...

Using Jest's moduleNameMapper with Next.js without TypeScript

I've been encountering some challenges trying to implement moduleNameMapper in NextJS using JavaScript. In this particular project, TypeScript is not being utilized. Next: 12.2.5 React: 18.2.0 Jest: 29.0.1 Jest environment jsdom: 29.0.1 Below is the ...

Develop a React component library and seamlessly integrate it into a Next.js project

Currently, I am in the process of building a component library using react js, vite tailwindcss, and antd. The components function flawlessly when running the project locally or within Storybook. However, upon importing them into another nextjs application ...

The server configuration is experiencing issues. For additional details, refer to the server logs

After configuring Google as an authentication provider with Next Auth and setting all the necessary environment variables for both production and development modes, everything works perfectly in development. However, when trying to sign in on the productio ...

Issue with Tailwind CSS when applying @apply directive

click here Hello all, I am currently working on a Nextjs project and attempting to utilize the @apply processor. However, I am encountering an error message as shown above. This is my package.json: { "name": "simon-bask-health-app", ...

Error in Next.js: Syntax error - unexpected token 'export'

I am encountering an issue while attempting to import a function from a dependency into my next/react functional component. The error message that keeps popping up is: SyntaxError: Unexpected token 'export' Here is the function I am trying to ...

What could be causing the slow compilation of my Next.js pages within the app directory, and what steps can be taken to improve the speed of this

Currently, I am working on a Next.js project that uses the 'app' directory structure. However, during local development, I have been facing significant delays in compile times. Here's a breakdown of the compile times I am encountering: - Th ...

No content sent in the request body while implementing fetch

Attempting to send graphql calls from a React component to a PHP server using the fetch method for the first time. The setup involves React JS on the client-side and Symfony 4 on the server-side. Despite indications that data is being sent in the browser ...

Navigating to a specific page utilizing Dynamic Routes in next.js

I am facing an issue where I need to route these URLs to [id].js file in next.js. Currently, everything is functioning correctly for URL 2 and 3 listed below, but unfortunately not for URL 1. This has led me to consider creating another index.js file, whic ...

When implementing Next.js layouts, the content will be displayed below the sidebar

I'm currently working on implementing a sidebar component for my app using mantine.dev, along with next.js layouts to ensure it is displayed on every page. The links within the sidebar are functioning properly, however, I am facing an issue where the ...

Problem encountered during NextJS build: ReferenceError - 'window' is undefined

While I am in the process of developing my app, I have encountered a perplexing issue with a ReferenceError: window is not defined. This error seems to be happening even though I am utilizing 'use client' "use client"; import React, { u ...

React's useState hook is not correctly updating the state variables when the form is submitted

const [user, setuser] = useState({ name: '', lastName: '', pass: '', mail: '', uName: '' }) const [nameError, setNameError] = useState(''); const [lastNameError, setLastNameError] = useState( ...

Ways to retrieve directory information in Next.js hosted on Netlify

Having trouble retrieving a list of directories in Next.js on Netlify. The code works fine on localhost, but once deployed to Netlify, an error is triggered: { "errorType": "Runtime.UnhandledPromiseRejection", "errorMessage": ...

Next.js API route is showing an error stating that the body exceeds the 1mb limit

I'm having trouble using FormData on Next.js to upload an image to the server as I keep getting this error. I've tried various solutions but haven't been able to resolve it yet. This is my code: const changeValue = (e) => { if (e.target ...

The element type 'x' in JSX does not offer any construct or call signatures

I have recently imported an image and I am trying to use it within a function. The imported image is as follows: import Edit from 'src/assets/setting/advertising/edit.png'; This is the function in question: function getOptions(row) { ...