Skip to content

chore: clarify runtimeConfig and process.env usage in nuxt.config #32223

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

Merged
merged 9 commits into from
Jul 7, 2025

Conversation

paranoidPhantom
Copy link
Contributor

🔗 Linked issue

Should resolve #32222

📚 Description

Clarified how runtime config works (I may be wrong in my clarification).

@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 15:07
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Clarify how process.env and runtimeConfig interact in nuxt.config.ts, emphasizing build-time values and override syntax

  • Added note that process.env in nuxt.config.ts returns build-time values
  • Explained overriding runtime config via NUXT_MY_VAR environment variables

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

coderabbitai bot commented May 27, 2025

Walkthrough

A clarification was added to the documentation specifying that in production, the runtimeConfig will not pick up environment variables unless they start with the prefix NUXT_. This update includes a reference link to the official Nuxt documentation on environment variables and runtime config. No modifications were made to any exported or public entities in the codebase.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/2.guide/2.directory-structure/2.env.md (1)

56-56: Fix spelling and improve clarity on runtimeConfig override.
There's a typo (“recieve”) and the sentence can be more precise.

Apply this diff:

- * Any time you access process.env in `nuxt.config.ts` you will recieve the baked in values from build time. The only way to override runtime variables is by using the `NUXT_MY_VAR` syntax to override `runtimeConfig`.
+ * Any time you access `process.env` in `nuxt.config.ts`, you will receive the baked-in values from build time. To override runtime config variables, use the `NUXT_MY_VAR` syntax to set values in `runtimeConfig` at runtime.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 726ac60 and 61acf9e.

📒 Files selected for processing (1)
  • docs/2.guide/2.directory-structure/2.env.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-docs

@paranoidPhantom paranoidPhantom requested a review from Copilot May 27, 2025 15:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR clarifies the distinction between build-time environment variables via process.env and runtime configuration in Nuxt.

  • Added a note in the documentation explaining that accessing process.env in nuxt.config.ts returns build-time values and that runtime overrides require the NUXT_MY_VAR syntax.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/2.guide/2.directory-structure/2.env.md (1)

58-60: Fix the typo and clarify warning phrasing
The link anchor contains a typo (#environment-variabes) and the sentence is a bit awkward. Consider rephrasing for clarity and correcting the anchor:

- ::warning
- If you are looking to update your environment variables in production, refer to [`runtimeConfig` docs](https://nuxt.com/docs/guide/going-further/runtime-config#environment-variabes) as using `process.env` in an attempt to read environment variables at runtime will not work.
+ ::warning
+ If you need to override environment variables at runtime in production, refer to the [`runtimeConfig` docs](https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables). Using `process.env` to read or update variables at runtime will not work.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~59-~59: Loose punctuation mark.
Context: ...ent variables at runtime will not work. :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b7f68d and 9cc87d4.

📒 Files selected for processing (1)
  • docs/2.guide/2.directory-structure/2.env.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/2.guide/2.directory-structure/2.env.md

[uncategorized] ~59-~59: Loose punctuation mark.
Context: ...ent variables at runtime will not work. :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-docs

Copy link
Contributor

@cybercoder-naj cybercoder-naj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth adding Alex's video on handling environment variables. There are more videos on his channel regarding nuxt's runtimeConfig.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/2.guide/2.directory-structure/2.env.md (1)

58-60: Refine grammar and punctuation for clarity
The sentence can be improved by using a semicolon, adding a comma around “therefore,” and using “cannot” instead of “can not” for a more natural style.
Apply this diff:

- `nuxt.config.ts` only runs at build time, therefore you can not change any aspect of it using environment variables at runtime.
+ `nuxt.config.ts` only runs at build time; therefore, you cannot change any aspect of it using environment variables at runtime.
🧰 Tools
🪛 LanguageTool

[typographical] ~59-~59: The word “therefore” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...ant nuxt.config.ts only runs at build time, therefore you can not change any aspect of it usi...

(THUS_SENTENCE)


[style] ~59-~59: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... only runs at build time, therefore you can not change any aspect of it using environme...

(CAN_NOT_PREMIUM)


[uncategorized] ~59-~59: Loose punctuation mark.
Context: ...using environment variables at runtime. :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cc87d4 and 5213325.

📒 Files selected for processing (1)
  • docs/2.guide/2.directory-structure/2.env.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/2.guide/2.directory-structure/2.env.md

[typographical] ~59-~59: The word “therefore” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...ant nuxt.config.ts only runs at build time, therefore you can not change any aspect of it usi...

(THUS_SENTENCE)


[style] ~59-~59: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... only runs at build time, therefore you can not change any aspect of it using environme...

(CAN_NOT_PREMIUM)


[uncategorized] ~59-~59: Loose punctuation mark.
Context: ...using environment variables at runtime. :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-docs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
docs/2.guide/2.directory-structure/2.env.md (2)

58-60: Improve clarity and correct grammar in the important note
The sentence conflates clauses and misuses “therefore” as a conjunction. Also hyphenate and change “can not” to “cannot” for consistency.

Proposed diff:

-::important
-`nuxt.config.ts` only runs at build time, therefore you can not change anything in it using environment variables at runtime (including runtimeConfig). Refer to Alexamder Lichter's video
-::
+::important
+`nuxt.config.ts` only runs at build time; you cannot change its configuration at run-time using environment variables (including `runtimeConfig`). Refer to Alexander Lichter’s video
+::
🧰 Tools
🪛 LanguageTool

[typographical] ~59-~59: The word “therefore” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...ant nuxt.config.ts only runs at build time, therefore you can not change anything in it using...

(THUS_SENTENCE)


[style] ~59-~59: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... only runs at build time, therefore you can not change anything in it using environment...

(CAN_NOT_PREMIUM)


62-64: Fix spelling and punctuation in the video tip
There’s a typo in “Alexamder” and the trailing punctuation could be tightened.

Proposed diff:

-::tip{icon="i-lucide-video" to="https://youtu.be/_FYV5WfiWvs" target="_blank"}
-Watch a video from Alexander Lichter showcasing the top mistake developers make using runtimeConfig.
-::
+::tip{icon="i-lucide-video" to="https://youtu.be/_FYV5WfiWvs" target="_blank"}
+Watch a video from Alexander Lichter showcasing the top mistake developers make using `runtimeConfig`.
+::
🧰 Tools
🪛 LanguageTool

[uncategorized] ~63-~63: Loose punctuation mark.
Context: ...ke developers make using runtimeConfig. :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5213325 and 651812e.

📒 Files selected for processing (1)
  • docs/2.guide/2.directory-structure/2.env.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/2.guide/2.directory-structure/2.env.md

[typographical] ~59-~59: The word “therefore” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...ant nuxt.config.ts only runs at build time, therefore you can not change anything in it using...

(THUS_SENTENCE)


[style] ~59-~59: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... only runs at build time, therefore you can not change anything in it using environment...

(CAN_NOT_PREMIUM)


[uncategorized] ~61-~61: Loose punctuation mark.
Context: ... Refer to Alexamder Lichter's video :: ::tip{icon="i-lucide-video" to="https://y...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~63-~63: Loose punctuation mark.
Context: ...ke developers make using runtimeConfig. :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-docs

@paranoidPhantom
Copy link
Contributor Author

I tried to improve the wording, but I am not sure if this is at all superior to just copying over the Environment Variables section of runtimeConfig guide (that would be duplicate info on two pages, which seems unnecessary to me).

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
docs/2.guide/2.directory-structure/2.env.md (2)

58-61: Fix grammar, punctuation and spelling in the important notice
The sentence currently contains a comma splice and a typo. Consider splitting into two clauses, use “cannot” instead of “can not”, and correct “Alexamder” to “Alexander”. For example:

 ::important
-`nuxt.config.ts` only runs at build time, therefore you can not change anything in it using environment variables at runtime (including runtimeConfig). Refer to Alexamder Lichter's video
+`nuxt.config.ts` only runs at build time; you cannot change its configuration at runtime (including `runtimeConfig`). Refer to Alexander Lichter's video for common pitfalls.
 ::
🧰 Tools
🪛 LanguageTool

[typographical] ~59-~59: The word “therefore” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...ant nuxt.config.ts only runs at build time, therefore you can not change anything in it using...

(THUS_SENTENCE)


[style] ~59-~59: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... only runs at build time, therefore you can not change anything in it using environment...

(CAN_NOT_PREMIUM)


[uncategorized] ~61-~61: Loose punctuation mark.
Context: ... Refer to Alexamder Lichter's video :: ::tip{icon="i-lucide-video" to="https://y...

(UNLIKELY_OPENING_PUNCTUATION)


62-64: Clarify the tip block wording
The tip icon and link are helpful—consider making the text more descriptive and consistent with the change above. For instance:

 ::tip{icon="i-lucide-video" to="https://youtu.be/_FYV5WfiWvs" target="_blank"}
-Watch a video from Alexander Lichter showcasing the top mistake developers make using runtimeConfig.
+Watch Alexander Lichter’s video on the top mistake developers make with `runtimeConfig`.
 ::
🧰 Tools
🪛 LanguageTool

[uncategorized] ~63-~63: Loose punctuation mark.
Context: ...ke developers make using runtimeConfig. :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 651812e and 91f3e5a.

📒 Files selected for processing (1)
  • docs/2.guide/2.directory-structure/2.env.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/2.guide/2.directory-structure/2.env.md

[typographical] ~59-~59: The word “therefore” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...ant nuxt.config.ts only runs at build time, therefore you can not change anything in it using...

(THUS_SENTENCE)


[style] ~59-~59: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... only runs at build time, therefore you can not change anything in it using environment...

(CAN_NOT_PREMIUM)


[uncategorized] ~61-~61: Loose punctuation mark.
Context: ... Refer to Alexamder Lichter's video :: ::tip{icon="i-lucide-video" to="https://y...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~63-~63: Loose punctuation mark.
Context: ...ke developers make using runtimeConfig. :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-docs

@danielroe
Copy link
Member

Maybe just link to that page instead?

I am not sure the current warning makes sense in the page about the .env file.

@paranoidPhantom
Copy link
Contributor Author

Maybe just link to that page instead?

I am not sure the current warning makes sense in the page about the .env file.

Sounds like the best option to me, now that I think about it.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/2.guide/2.directory-structure/2.env.md (1)

58-61: Fix Markdown link formatting and clarify wording.

Current link syntax in the admonition block is invalid and may not render properly. Also rephrase for clarity and point directly to the Runtime Config documentation:

::important
- `runtimeConfig` [won't pick up environment variables that don't start with `NUXT_` in production] (https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables).
+ `runtimeConfig` won’t pick up environment variables that don’t start with `NUXT_` in production. For more details, see [Runtime Config Environment Variables](https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables).
::
🧰 Tools
🪛 LanguageTool

[uncategorized] ~59-~59: Loose punctuation mark.
Context: .../runtime-config#environment-variables). :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91f3e5a and 52bde94.

📒 Files selected for processing (1)
  • docs/2.guide/2.directory-structure/2.env.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/2.guide/2.directory-structure/2.env.md

[uncategorized] ~59-~59: Loose punctuation mark.
Context: .../runtime-config#environment-variables). :: ## Production Preview For local prod...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-docs

@paranoidPhantom
Copy link
Contributor Author

@danielroe Would love some feedback 🙏

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you ❤️

@danielroe danielroe merged commit 9b8da9d into nuxt:main Jul 7, 2025
13 of 14 checks passed
@github-actions github-actions bot mentioned this pull request Jul 7, 2025
@github-actions github-actions bot mentioned this pull request Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: process.env usage within nuxt.config is unclear and unintuitive (needs clarification)
6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy