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.

Environment variables no longer passed to app in 9.5 ("ReferenceError: process is not defined")

See original GitHub issue

Bug report

Describe the bug

Process object used to access environment variables in node is missing after upgrading to 9.5.

To Reproduce

Upgraded to nextjs 9.5 and the snippet in the screenshot broke. If I start the app using a command like this NEXT_PUBLIC_LOCAL_FUNCTIONS_PORT=5001 next it works, but if I leave out the environment in the command (i.e. next) it fails.

Tried creating a fresh next app (on 9.5) and was NOT ABLE to reproduce. Might be something with my dependencies.

Expected behavior

I expected that env variables would be able to be looked up on the client.

Screenshots

Screen Shot 2020-07-28 at 7 15 29 AM

System information

  • OS: macOS
  • Browser: Chrome 84.0.4147.89
  • Version of Next.js: 9.5
  • Version of Node.js: 10.20.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
Ymirkecommented, Jan 4, 2021

@7iomka it is not possible to use destructuring with process.env in next.js. Line 17 is an error, but you can still define them one by one and it should work.

export const BACKEND_URI = process.env.BACKENDURI
// ...
// ...

Explaination about why is here: https://github.com/vercel/next.js/issues/6888. It is because of a webpack plugin.

4reactions
berakoccommented, Mar 28, 2021

@7iomka it is not possible to use destructuring with process.env in next.js. Line 17 is an error, but you can still define them one by one and it should work.

export const BACKEND_URI = process.env.BACKENDURI
// ...
// ...

Explaination about why is here: #6888. It is because of a webpack plugin.

Destructuring env variables caused process is not defined error. By exporting them one by one, my app is working just fine. Thank you so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: “process is not defined” - GIMTEC
In NodeJS, “process” is defined, but not in the browser. This is because NodeJS and the browser are different runtime environments.
Read more >
javascript - Uncaught ReferenceError: process is not defined
Node.js code must be run by the node process, not the browser (the code must run in the server). To run the code,...
Read more >
Firebase JavaScript SDK Release Notes - Google
The SDK no longer causes React Native to log a warning about deprecation of AsyncStorage ... where the SDK tried to access fields...
Read more >
process is not defined / how to use environment variables in ...
I have a plain HTML/CSS/JavaScript page - no Node, no frameworks, just plain old HTML/CSS/JS. How do I access environment variables from my...
Read more >
Passing the environment variables to Cypress - YouTube
Using either --env or plugin file. The plugin file way is the most powerful way to pass the environment variables, plus it makes...
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