Skip to content

fix: gate npm installs on the node version preflight - #7210

Merged
masenf merged 6 commits into
reflex-dev:mainfrom
flcrom:fix/npm-preflight-before-install
Sep 24, 2026
Merged

masenf merged 6 commits into
reflex-dev:mainfrom
flcrom:fix/npm-preflight-before-install

Conversation

@flcrom

@flcrom flcrom commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #6976.

A warm app running REFLEX_USE_NPM=1 reflex run with unsupported Node.js could install frontend packages and persist npm lockfiles before failing its version check. Later plain runs would then use npm because of the saved lockfiles.

Check the selected package manager's Node.js requirement before npm installation or lockfile synchronization. This also covers npm selected when Bun is unavailable. Keep Bun independent of the Node.js version, and defer initialization checks so they do not prevent Bun setup.

Regression tests cover rejected and supported npm installs, Bun, and initialization. Mocked package-manager tests also stub their Node.js prerequisite and fail if they inspect the host Node installation. The changelog fragment uses this PR's number.

Validation: the full unit suite, Ruff lint and formatting, Pyright, and codespell pass. The focused install tests also pass with a shim reporting an unsupported Node.js version. In a real app, the base branch changed persisted lockfiles before rejecting Node.js; this branch left them byte-identical and the next plain run used Bun. Supported npm and Bun browser interactions and production exports passed.

Review in cubic

@flcrom
flcrom requested a review from a team as a code owner September 19, 2026 06:09
@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; both previously reported package-manager gating defects are fixed and no new actionable issues were identified.

Summary

This PR prevents npm from running with an unsupported Node.js version before package installation or lockfile synchronization can mutate project state.

  • Gates both explicitly selected npm and npm selected when Bun is unavailable.
  • Keeps Bun installation and execution independent of the Node.js version.
  • Defers initialization validation where necessary to allow fresh Bun setup.
  • Adds regression coverage for npm fallback, supported and unsupported Node versions, Bun behavior, initialization, and lockfile side effects.
  • Includes a user-facing bugfix news fragment.

Reviews (6) · Last reviewed commit: "Compare bun lockfile prune path portably..."

Comment thread reflex/utils/js_runtimes.py Resolved
@codspeed

codspeed Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 129 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing flcrom:fix/npm-preflight-before-install (aa81702) with main (6a0959b)2

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (b7dd25a) during the generation of this report, so 6a0959b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread reflex/utils/js_runtimes.py Resolved
Comment thread reflex/utils/js_runtimes.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread reflex/utils/js_runtimes.py Resolved
Comment thread tests/units/utils/test_js_runtimes.py Resolved
Instinct Agent and others added 4 commits September 19, 2026 13:56
Restore the up-front Node.js check during init when npm is explicitly
preferred: install_bun skips bun setup in that case, so deferring the
check let init finish on an unsupported Node.js. Only the npm-fallback
case is deferred until after bun setup.

Reuse the executor already resolved at run time instead of looking up
package managers again, drop the unreachable empty-list guard, and trim
the comments. Tests cover explicit-npm init, the error message and the
bun lockfile pruning; the host-probe test that could not fail is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01F81q6RZRQqtp3nAniyCXV5
str(Path("/usr/bin/bun")) is backslash-separated on Windows, so compare
against the same Path object the discovery stub returns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01F81q6RZRQqtp3nAniyCXV5
@masenf
masenf merged commit 3be360d into reflex-dev:main Sep 24, 2026
126 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants