question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Source all environment variables in order to match Next

See original GitHub issue

🐛 Bug Report

The library only loads environment variables when they’re prefixed with NEXT_PUBLIC_.

https://github.com/toomuchdesign/next-page-tester/blob/a483a65fd228587f16f2ced52909acc2b42d459d/src/setEnvVars.ts#L24-L26

However, this is different than Next’s behavior. These “private” environment variables are indeed made available to SSR and build functions, such as getStaticProps.

Reproduction

Simply require an environment variable without a NEXT_PUBLIC_ prefix in a getStaticProps function, for example. It will be undefined.

Expected behavior

In order to match Next and expected functionality, these variables should be available to build and server runtime functionality.

Jest patch

Have you patched Jest as described here?

  • yes
  • no

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Linux 5.11 Arch Linux
    CPU: (20) x64 Intel(R) Core(TM) i9-7900X CPU @ 3.30GHz
  Binaries:
    Node: 15.9.0 - ~/.nvm/versions/node/v15.9.0/bin/node
    npm: 7.5.3 - ~/.nvm/versions/node/v15.9.0/bin/npm
  npmPackages:
    jest: ^26.6.3 => 26.6.3

Thanks for your work on this very helpful test library.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
toomuchdesigncommented, Mar 20, 2021

The issue affected only getStaticProps. It was an actual missing implementation detail 👍 Fixing with #197

0reactions
brettinternetcommented, Mar 20, 2021

Hi @toomuchdesign, sorry for the delay. Thank you very much for your fix!

Read more comments on GitHub >

github_iconTop Results From Across the Web

List all environment variables from the command line
To show certain variable such as 'PATH', use SET PATH . For help, type set /? . Share.
Read more >
How To Read and Set Environmental and Shell Variables on ...
We can see a list of all of our environmental variables by using the env or printenv commands. In their default state, they...
Read more >
An Introduction to Environment Variables and How to Use Them
Next, let's look at how to utilize environment variables using the native operating system, the NPM package dotenv, and webpack.
Read more >
Next.js environment variables - Refine Dev
Basically, environment variables are added into Next.js apps through a env.local file. This will then load every variable into the Node.js ...
Read more >
What are PATH and other environment variables, and how ...
What are Environment Variables? Environment variables hold values related to the current environment, like the Operating System or user sessions. Path.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found