Skip to content
Putting technology to work.
Insights to guide decisions and action.

Search articles

Nuxt 4.7: stop missing environment variable settings at startup

Table of contents · 9 items

For example, if you forget to set the environment variable for a newly added API key in production, only the production environment fails to connect to the external API. In web apps built with Nuxt, API keys and connection targets are placed in runtimeConfig and overridden per environment with environment variables starting with NUXT_. Until now, Nuxt started with the default values even when environment variables were missing, and errors did not surface until the code that used those values ran.

Nuxt released 4.7.0 on November 23 and 4.7.1 on November 30. In 4.7, you can declare runtimeConfig values with schemas such as Zod, and if there are errors such as a missing required value or a mismatched type or allowed value, the server will not start. 4.7.0 also includes fixes for three security issues (covered in a later section).

In this article, based on Nuxt's official blog and documentation, the advisories in the nuxt/nuxt repository, and the results of passing the same environment variables to 4.6.4 and 4.7.1 in a test environment, we summarize what to rewrite and what to watch out for.

How environment variables were handled until now

According to the Nuxt documentation, environment variable values are converted to JavaScript types with destr. As an example, it says NUXT_MY_VAR=4848e0 becomes the number 4848. To receive the value as a string, the value itself must include double quotes.

The Nuxt 4.7 official blog gives the reasons for introducing schemas as follows: with the previous runtimeConfig, types were determined from default values, required and allowed values could not be declared, and “strings that look like numbers” such as 4848e0 could be converted to numbers.

Specifying schemas in Nuxt 4.7

You can write a schema compatible with Standard Schema (and Standard JSON Schema) for each value in runtimeConfig. The documentation gives Zod, ArkType, and Valibot wrapped in toStandardJsonSchema() as examples. No experimental feature setting (experimental) is needed; it takes effect just by writing a schema in runtimeConfig. In the tests in a later section, we also did not set experimental.

import { z } from 'zod'

export default defineNuxtConfig({
  runtimeConfig: {
    apiSecret: z.string(), // 既定値なし=必須
    session: z.object({
      maxAge: z.number().int().default(3600),
    }),
    public: {
      buildId: z.string().default(''),
      mode: z.enum(['preview', 'production']).default('production'),
    },
  },
})

The behavior described in the documentation is as follows.

  • Values without a default become required. A warning is shown at build time, and the server will not start until a value is provided
  • Environment variables are converted to the schema's type. The server also will not start if a value cannot be converted or is not among the allowed values (the error is NUXT_E8014)
  • The schema itself is not included in the server bundle. At build time, it is converted into a small description containing only the type, whether the value is required, and the allowed values
  • Fine-grained conditions (refinements) such as minimum length or URL format are not validated, and value conversions (transforms) cannot be used
  • For schemas declared by modules, the server still starts with only a warning unless compatibilityVersion: 5 is enabled

Results with the same environment variables

In a test environment (Node.js v22.23.5), we created three apps with the same page and server API (which only returns the config values and their types): one on 4.6.4 with only default values, one on 4.7.1 with only default values, and one on 4.7.1 with the schema above. For each, after nuxt build, we started .output/server/index.mjs while changing only the environment variables (one run each).

Results of passing the same environment variables to three Nuxt configurations. When 4848e0 was passed to NUXT_PUBLIC_BUILD_ID, 4.6.4 and 4.7.1 with only default values turned it into the number 4848, while 4.7.1 with a schema kept it as the string 4848e0. When NUXT_API_SECRET was missing, the first two started and the schema configuration did not. When abc was passed to maxAge and staging to mode, the first two accepted them as is, and the schema configuration did not start

  • NUXT_PUBLIC_BUILD_ID=4848e0: In 4.6.4 and in 4.7.1 with only default values, it became the number 4848. With the schema configuration, it remained the string "4848e0"
  • Not passing NUXT_API_SECRET: 4.6.4 and the defaults-only configuration started, with the key left as an empty string. The schema configuration displayed “apiSecret is required. Set NUXT_API_SECRET or provide a default.” and did not start
  • NUXT_SESSION_MAX_AGE=abc and NUXT_PUBLIC_MODE=staging: 4.6.4 and the defaults-only configuration started with maxAge as the string "abc" and mode as "staging". The schema configuration displayed both errors together and did not start

Simply upgrading to 4.7.1 did not change how environment variables were handled compared with 4.6.4. Only values with a schema are validated.

Even at build time, in an environment where NUXT_API_SECRET was not set, the warning “[NUXT_B5032] The runtime config does not match its schema with the current environment” appeared. The build succeeds.

Steps for rewriting (editorial suggestion)

  1. Make a list of environment variables. Write down the NUXT_ variables set in each of the development, staging and production environments, and map each one to the corresponding value in runtimeConfig
  2. Rewrite required values first. Turn values the app cannot run without, such as API keys and connection targets, into schemas without defaults, such as z.string(). For values that used an empty string as the default, decide whether to make them required or .optional()
  3. Use enums for values with a fixed set of options. Making a value such as mode a z.enum() lets a typo stop startup
  4. Check for warnings in CI builds. Confirm that NUXT_B5032 does not appear in a build given the same variables as production. If it does, either a production setting is missing or the schema is wrong
  5. Check startup in staging. Because a startup failure stops the app, start it in staging with the same variables before production

Because fine-grained conditions are not validated, continue to check key length and URL format in the code that uses them. Also, stopping at startup works on the safe side when your deployment system can detect a startup failure of the new version and roll back to the previous one. With systems that cannot roll back, a missing setting can take the service down, so put steps 4 and 5 in place first.

Three security issues fixed in 4.7.0

On November 24, three advisories were published in the nuxt/nuxt repository. The official blog also says “This release fixes three security issues. We recommend upgrading.” and recommends updating. All three are fixed from 4.7.0, and no fixed release has been issued for 4.6.x. No fixed release is indicated for the affected Nuxt 3 versions either.

  • GHSA-jxc9-w3j6-pwp2 (severity Medium): An issue where a page's route rules are not applied to the page's data URLs (such as /admin/_payload.json). It applies when you combine isr, swr or cache rules such as '/**': { swr: 60 } with per-page redirect, proxy, headers or ssr: false, or settings that exclude pages from caching. Page data protected by redirects or proxying could be read, or per-user data could be cached and returned to other users. The official blog recommends that if you used these rules on pages with per-user data, you purge _payload.json from CDN and other caches after updating
  • GHSA-vrh2-cfcx-c3fg (severity Medium): An incomplete fix for GHSA-f3x9-2chm-73c8, which was fixed in 4.6.4. On catch-all pages (such as pages/[...slug].vue), route rules (such as appMiddleware and redirect) are not applied when slashes are doubled, as in //admin/secret, or when the path starts with %2F, as in /%2Fadmin/secret
  • GHSA-h5xj-x893-p5f7 (severity Low, development only): An incomplete fix for GHSA-648h-gw55-m2g7. If nuxt dev is exposed to the network, private runtime config values determined at build time can be read from the output of a previously run nuxt build or nuxt generate. Values left empty in nuxt.config and passed at server startup via NUXT_ environment variables are not included in the output and are therefore not affected

As of December 1, the three advisories are not listed in the GitHub Advisory Database and have no CVE numbers. npm audit, which refers to the database, is likely not to show warnings yet. Check the actual installed version with npm ls nuxt.

The third issue also relates to the runtime config discussed in this article. The 4.7.1 documentation states that values written in nuxt.config (including values read from process.env) are written into the server build output, and says to leave private values empty in nuxt.config and pass them via NUXT_ environment variables. A z.string() schema without a default fits this pattern (editorial summary).

Caution when freshly reinstalling 4.6.x

The three issues in the previous section are not fixed in the 4.6 line, so unless you have a reason to stay on 4.6, upgrade to 4.7.1. If you reinstall while staying on the 4.6 line, keep the following in mind.

In our testing, nuxt build stopped with a Vite error, "INVALID_EXTERNAL_ID", in an environment where 4.6.4 was freshly installed (we tried twice with the same result). The Vite version installed at that time was 8.4.0, released on November 26. The @nuxt/vite-builder range that 4.6.4 depends on is ^8.3.5, and 8.4.0 falls within that range. When we pinned Vite to 8.3.8 with overrides in package.json, the build succeeded. With 4.7.1, the build succeeded while staying on Vite 8.4.0. According to the npm records, the @nuxt/vite-builder range is ^8.3.8 in 4.7.0 and ^8.4.0 in 4.7.1.

If you commit your lockfile (such as package-lock.json), reinstalling does not change the Vite version. If your CI installs without using the lockfile, you may run into this issue. We covered the changes in Vite 8.4 in our article on Vite 8.4's allowlist approach.

When updating from the 4.6 line, also check our article on nuxt/server in 4.6 and our article on the issue where route rule protections could be bypassed. Of the advisories in the previous section, GHSA-h5xj-x893-p5f7 is an incomplete fix for GHSA-648h-gw55-m2g7, mentioned in article 1012, and GHSA-vrh2-cfcx-c3fg is an incomplete fix for GHSA-f3x9-2chm-73c8, covered in article 1144.

Other changes in 4.7

The official blog lists the following additional changes. Nitro v3 and staticRoutes are features you enable by adding settings or dependencies.

  • Nitro v3 is available to try: Adding nitro as a dependency makes the build use Nitro v3, the foundation of Nuxt 5. The official blog calls it "highly experimental" and advises trying it on a branch rather than in production. It also notes that the interpretation of route rule pattern syntax changes
  • experimental.staticRoutes: For apps that do not add routes at runtime, the server route matcher is built only once. Features such as router.addRoute() can no longer be used
  • Deprecation of <NuxtClientFallback>: The new retry-on-client in <NuxtErrorBoundary> replaces it
  • Before upgrading: Nuxt DevTools is no longer installed together with Nuxt (add @nuxt/devtools if you use it). 4.7 requires ^3.5.46 of vue, and if it is outdated, a NUXT_B7042 warning appears. The official blog recommends npx nuxt upgrade --dedupe for updating

Scope of verification

On December 1, 2026, we checked the official Nuxt blog (on nuxt.com and content/blog/50.v4-7.md in the nuxt/nuxt.com repository, where the source is kept), the documentation (on nuxt.com and docs/3.guide/6.going-further/10.runtime-config.md and docs/errors/e8014.md at tag v4.7.1 of nuxt/nuxt), the release notes for v4.7.0 and v4.7.1, the advisories in the nuxt/nuxt repository (retrieved via the GitHub API) and whether they are listed in the GitHub Advisory Database, and the npm publication dates and dependency ranges (document research). On the same day, in a test environment, we used Node.js v22.23.5, Nuxt 4.6.4 (Vite 8.3.8) and 4.7.1 (Vite 8.4.0), and Zod 4.6.7, and started the built server with different environment variables (hands-on testing, once each). We have not verified behavior in the dev server (nuxt dev), prerendering, schemas declared by modules, compatibilityVersion: 5, or runtimes other than Node.js such as Cloudflare Workers, nor Nitro v3, nor reproduced the three security issues.

For maintenance and version updates of business systems and web apps built with Nuxt, contact us via Development, AI and automation consultation.

References

Share this articleXFacebook
Kakeru Suzuki

Fascinated by the possibilities of technology, has had a deep interest in programming and digital art since student days

Turn this article's theme into your company's next step

Concrete steps forward for your organization.

We organize your desired architecture, legacy systems, and operational requirements to formulate your next steps toward execution.

  • Desired architecture
  • Integration with existing environments
  • Operational requirements
Consult on development & operations initiatives

You can consult with us from the initial conceptual stage. Details from this article will be carried over to the inquiry form.

Receive the latest articles by email