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.

Standalone output does not load runtimeConfig from environment variables

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
Binaries:
  Node: 18.2.0
  npm: 8.9.0
  Yarn: 1.22.18
  pnpm: 7.3.0
Relevant packages:
  next: 12.2.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Docker with node .next/standalone/server.js

Describe the Bug

When running the standalone server using node .next/standalone/server.js the server does not load any of the runtimeConfig values from the environment variables, hardcoded values do work. It does get loaded when running the server using next start.

Setting those environment variables during build time does show them when running the server, but that kind of beats the point of using the runtimeConfig and might make for really confusing interactions (it took me for a run).

Expected Behavior

That running node .next/standalone/server.js will load the runtimeConfig variables that are set using an environment variable during runtime.

Link to reproduction

https://github.com/blurrah/next-runtime-standalone-bug

To Reproduce

  • Build the server using yarn build
  • Run the server using TEST_VALUE=test node .next/standalone/server.js
  • You will just see a dash returned on the homepage

When running the server using TEST_VALUE=test yarn start it will work properly and return test - test.

Using TEST_VALUE=test yarn build -> node .next/standalone/server.js also returns test - test.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ShadiBlitzcommented, Jul 12, 2022

@ijjk Thanks. But what is the approach to be able to read environment variables dynamically at runtime from a docker container for a standalone build (that can be read by the client too…) ?

1reaction
durdocommented, Jul 11, 2022

I ran into this and would like to understand where we stand on it:

  1. Shouldn’t this behavior be documented in the output: "standalone" section of the docs?
  2. Is there a plan to fix this behavior for future releases?
  3. Is there and custom server I can use as an example to solve this?
Read more comments on GitHub >

github_iconTop Results From Across the Web

next.config.js: Runtime Configuration
Note: This feature is considered legacy and does not work with Automatic ... Please use environment variables instead in order to avoid initialization ......
Read more >
Buildtime vs runtime environment variables with Next.js and ...
Below MY_VAR is an environment variable available to next build . Note that MY_VAR is not available to next start . ARG statements...
Read more >
Runtime configuration settings - Pega Robotic Automation Help
If the RuntimeConfig.xml file is also missing from the installation directory, Runtime will not start. Deployment package security. To use deployment package ...
Read more >
Why is runtimeConfig doesn't see environment variables in ...
env && node .output/server/index.mjs. Note that for a purely static site, it is not possible to set runtime configuration config after your ...
Read more >
dotnet publish command - .NET CLI | Microsoft Learn
The dotnet publish command's output is ready for deployment to a ... You don't have to run dotnet restore because it's run implicitly...
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