Skip to content

Failed REFLEX_USE_NPM run persists an inconsistent reflex.lock (npm↔bun switch breaks subsequent runs) #6976

Closed

Description

@masenf

Describe the bug

A reflex run under REFLEX_USE_NPM=1 that fails preflight (node version check) still persists lockfile state into reflex.lock/ — and persists an inconsistent trio: npm rewrites the .web/package.json pins to caret ranges (npm's default save-prefix) and creates package-lock.json, which get copied into reflex.lock/ alongside the now-stale exact-spec bun.lock. The next plain (bun) run then fails bun install --frozen-lockfile.

To Reproduce

  1. Make the node version check fail, e.g. put a shim first on PATH that prints an old version:
    mkdir fakenode && printf '#!/bin/sh\nif [ "$1" = "-v" ]; then echo v22.12.0; else exec /usr/bin/node "$@"; fi\n' > fakenode/node && chmod +x fakenode/node
    PATH=$PWD/fakenode:$PATH REFLEX_USE_NPM=1 reflex run --frontend-port 3463 --backend-port 8465
    The run fails on the node-version error — but by then the npm install has already run, .web/package-lock.json exists, and {bun.lock, package-lock.json, package.json} are copied into reflex.lock/, with package.json rewritten to caret ranges while bun.lock keeps exact specs.
  2. Run normally (bun, real node): reflex run ...

Observed behavior

bun install --frozen-lockfile
error: lockfile had changes, but lockfile is frozen

and reflex aborts telling the user to delete reflex.lock. (The recovery advice works: after rm -rf reflex.lock the next run regenerates a clean bun-only lock.)

Expected behavior

A run that failed preflight should not have mutated persisted lockfile state at all; and switching package managers (npm↔bun) should invalidate/regenerate the other manager's lockfile instead of persisting an inconsistent trio.

Root cause (from source)

install_frontend_packages never invalidates the other package manager's persisted lockfile on a manager switch: an npm-primary install rewrites .web/package.json pins to caret ranges and creates package-lock.json, then sync_web_lockfiles_to_root persists them ALONGSIDE the stale exact-spec bun.lock; on the next run _persisted_lockfile_implies_npm() returns False because bun.lock exists, so bun runs install --frozen-lockfile against a package.json that no longer matches bun.lock and correctly refuses. Newly exposed in 0.9.9a1 by removing the postcss entry from PackageJson.OVERRIDES, which previously made the npm path fail (EOVERRIDE) before any lockfile persistence. Also, the fatal node-version error fires only AFTER _compile_app() has already run the full npm install. Fix directions: use --save-exact on npm-primary installs and/or drop/regenerate the other manager's lockfile on switch, or prefer npm when reflex.lock carries a package-lock.json newer than bun.lock.

Specifics (please complete the following information):

  • Python Version: 3.11
  • Reflex Version: 0.9.9a1
  • OS: linux

Additional context

Activity

  1. added
    bug
    on Aug 28, 2026
  2. linear-code commented on Aug 28, 2026

    @linear-code
  3. added
    release-train
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrelease-train

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions