Skip to content

__DEV__ is not defined: dev server renders blank page on Vite 8 (Slidev v52) #2665

Description

@ocean-sudo

Describe the bug

When NODE_ENV=production is set in the shell environment, slidev (dev server) renders a completely blank white page. The JavaScript console shows: ReferenceError: __DEV__ is not defined.

Root cause: @slidev/client/env.ts uses export const mode = __DEV__ ? 'dev' : 'build', but __DEV__ is not a standard Vite variable — it was auto-defined by older Vite versions via a Vue compatibility shim, and Vite 8 no longer guarantees it. When NODE_ENV=production is present, Vite 8's import.meta.env.DEV reports false even in dev server mode, and the __DEV__ define (which Slidev's getDefine() correctly maps to options.mode === "dev") doesn't take effect.

The fix is a one-line change: replace __DEV__ with Vite's standard import.meta.env.DEV, which correctly reflects the Vite mode regardless of NODE_ENV.

Minimal reproduction

Steps to reproduce:

  1. export NODE_ENV=production
  2. pnpm create slidev (or npm create slidev@latest) — Slidev v52.17.0
  3. pnpm run dev
  4. Open http://localhost:3030 → completely blank page
  5. Check console: ReferenceError: __DEV__ is not defined

You can use https://sli.dev/new to create a new project.

This is reproducible whenever NODE_ENV=production is present — common in CI/CD environments, Docker containers, or developer machines with global NODE_ENV set.

Proposed fix

In @slidev/client/env.ts, line 5:

- export const mode = __DEV__ ? 'dev' : 'build'
+ export const mode = import.meta.env.DEV ? 'dev' : 'build'

import.meta.env.DEV is the standard Vite API for detecting dev mode. It correctly reports true in dev server and false in production builds, and is NOT affected by NODE_ENV. This fix:

  • ✅ Fixes the bug when NODE_ENV=production
  • ✅ No change in behavior when NODE_ENV is unset or development
  • ✅ No change in production build behavior (import.meta.env.DEV is false at build time)
  • ✅ Eliminates dependency on the non-standard __DEV__ global

Workaround (until fixed)

// package.json
"dev": "NODE_ENV=development slidev"

Environment

  • Slidev version: 52.17.0
  • Node: v26.2.0
  • pnpm: v11.11.0
  • OS: macOS 26.5.2

Additional context

Related to closed issue #2142 (same error, closed without root cause analysis — the reporter likely had NODE_ENV=production set without realizing it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions