Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to locate .env variables defined in the server side #59

Closed
Shadid12 opened this issue Jan 25, 2023 · 1 comment
Closed

Unable to locate .env variables defined in the server side #59

Shadid12 opened this issue Jan 25, 2023 · 1 comment

Comments

@Shadid12
Copy link

Unable to access the defined environment variables in the Next.js getServerSideProps() function.

To reproduce:

  1. Create some new environment variables by going to Pages > your Pages project > Settings > Environment variables
  2. Screen Shot 2023-01-25 at 7 08 34 AM
  3. Add the following code in your index.js file
export const config = {
  runtime: 'experimental-edge',
}


export async function getServerSideProps() {
  const fauna_secret = process.env.FAUNA_SECRET;
  const node_env = process.env.NODE_VERSION;
  const products = await getProducts();
  return {
    props: {
      products,
      fauna_secret,
      node_env
    },
  }
}


export default function Home({ products, fauna_secret, node_env }) {
  console.log(products);
  console.log('===>', fauna_secret); // will be undefined
  console.log('===>', node_env);  // will be undefined
  return (
    <div className={styles.container}>
      <h1>Products</h1>
      ...
      </ul>
    </div>
  )
}
  1. Deploy
  2. Notice environment variables are going to be undefined
@GregBrimble
Copy link
Member

Closed as duplicate of #1

@GregBrimble GregBrimble closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants