Skip to content

bug: [email protected] crashes on Node < 20.12 with "node:util has no export named styleText" before engine check #1909

Closed as not planned

Description

@l246804

Describe the bug

Running vpr <script> in a project pinned to a Node.js version that does not yet have util.styleText (added in Node 20.12 / 22) crashes at module load time, before any of vp's own engine-compatibility checks can run:

file:///~/.vite-plus/0.2.1/node_modules/.pnpm/[email protected][email protected]/node_modules/vite-plus/dist/terminal-uTv0ZaMr.js:2
import { styleText } from "node:util";
         ^^^^^^^^^
SyntaxError: The requested module 'node:util' does not provide an export named 'styleText'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:98:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:143:5)
    at async Loader.import (internal/modules/esm/loader.js:165:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)

Source:

// vite-plus/dist/terminal-uTv0ZaMr.js
import { styleText } from "node:util";

styleText was added in Node 20.12 and only stabilized in v22, so any project whose .node-version resolves to Node 14 / 16 / 18.x < 20.12 will hit this SyntaxError during ESM instantiation of the terminal helper — i.e. before vp's own "Node.js X is incompatible with Vite+ CLI" message has a chance to fire, and before the script-runner soft-fallback work tracked in #1875 (PR #1865 / #1874) can take effect.

This makes vpr completely unusable in older repos even as a thin script forwarder, which is exactly the use case #1875 was supposed to preserve.

Suggested fix

Either:

  1. Avoid the static import { styleText } from "node:util" in any module that can be loaded before the engine check (in particular terminal-*.js, which the CLI bootstrap pulls in eagerly). A small pc-style fallback or a dynamic import gated on process.versions.node >= 20.12 would let the runner reach the vpr soft-fallback path; or
  2. Build the CLI bootstrap chunk with a downlevel target so static imports don't reference Node-22-only named exports.

Reproduction

Any project with a .node-version pinning Node ≤ 20.11 (reproduced on 14.15.0). Steps:

  1. In a directory with .node-version containing 14.15.0 (or use vp env use 14.15.0).
  2. vpr dev (or any vpr <script> — fails before reaching the script).

Result: the SyntaxError above. Expected: the soft-fallback behavior from #1875, or at minimum the previous "Node.js X is incompatible with Vite+ CLI" diagnostic.

Steps to reproduce

echo 14.15.0 > .node-version
vpr dev

System Info

$ vp env current
VITE+ - The Unified Toolchain for the Web

Environment:
  Version       14.15.0
  Source        .node-version
  Source Path   /home/<me>/<project>/.node-version
  Project Root  /home/<me>/<project>

Tool Paths:
  node  ~/.vite-plus/js_runtime/node/14.15.0/bin/node
  npm   ~/.vite-plus/js_runtime/node/14.15.0/bin/npm
  npx   ~/.vite-plus/js_runtime/node/14.15.0/bin/npx

$ vp --version
VITE+ - The Unified Toolchain for the Web
vp v0.2.1

Local vite-plus:
  vite-plus  Not found

Environment:
  Package manager  npm latest
  Node.js          v14.15.0 (.node-version)

Used Package Manager

npm

Related

Validations

Activity

  1. fengmk2 commented on Jun 22, 2026

    @fengmk2
    Member
  2. l246804 commented on Jun 22, 2026

    @l246804
    Author

    I understand bumping engines to ^20.19.0 — Vite+ core needn't support Node 14. But I'd like to suggest another angle: when vpr detects an unsupported Node version, degrade to pure passthrough — load no Vite+ JS at all, and have the Rust layer directly fork the project's own package manager to run the script. Scoped to vpr only.

    Why this matters

    Many enterprise projects are still pinned to older Node and can't be upgraded short-term due to process and compatibility constraints. The value of vpr as a script runner (#1875) is one muscle memory across every repo; if low-Node repos force a fallback to nr / npm run, that universality is lost.

    Sketch

    Version check in the Rust trampoline (no Node module loader involved):

    Node version >= engines.min
      yes → existing vite-plus CLI path
      no  → reuse existing package-manager detection,
            exec npm/pnpm/yarn run <script>, forward exit code
    

    Benefits

  3. fengmk2 commented on Jun 22, 2026

    @fengmk2
    Member

    Good suggestion. Are you willing to try to implement it?
    One relatively challenging thing is how to continuously ensure that the vpr command will not be compromised by subsequent new features. It is necessary to consider adding continuous validation test cases.

  4. l246804 commented on Jun 22, 2026

    @l246804
    Author

    Thanks! Unfortunately I'm not proficient in Rust and don't feel confident delivering a production-quality patch — it'd be safer for someone more familiar with the codebase to take it on, but I'm happy to help with testing and drafting validation cases.

  5. l246804 commented on Jun 23, 2026

    @l246804
    Author

    Adding to the shim scope: on low Node, vp i (project install) breaks the same way as vpr, and worse — it leaves devEngines.packageManager = [email protected] in package.json and routes every npm call to an npm version incompatible with the active Node (npm 11 needs Node ≥20.17; under Node 14 it throws Cannot find module 'node:path'). So not only is vp i unusable on low Node, it also breaks manual npm i / npm run dev afterward.

    Filed as a separate, independently-reproducible bug: #1916. The passthrough/shim idea here should cover both vpr and vp i — at minimum, on unsupported Node, forward to the Node-bundled package manager instead of loading Vite+ JS or pinning an incompatible npm.

  6. added a commit that references this issue on Jun 24, 2026
    3a95df9
  7. liangmiQwQ commented on Jun 24, 2026

    @liangmiQwQ
    Collaborator

    I am a bit worried about whether it is a long-term, sustainable plan. vp run relies on Vite Task, delegating to the underlying package manager makes vp run have two different behaviors in many locations, a command with two different semantic decided by node version (#1921) without any explicit config is quite confusing. What's more, it can only help improve global cli use, local cli still has to run JavaScript.

    Maybe a more fundamental is putting off some incompatible code until after runtime/engine checks, and avoiding failing while loading or resolving modules, like switching to picocolors rather than node:util#styleText.

  8. l246804 commented on Jun 25, 2026

    @l246804
    Author

    I also lean toward @liangmiQwQs direction — avoiding module-load-time breakage is more sustainable than a passthrough shim. That said, replacing APIs like node:util#styleText with polyfills such as picocolors across the codebase would carry non-trivial maintenance cost, and could slow adoption of newer Node APIs in the future.

    An alternative worth considering: an explicit opt-in config for legacy Node support at the project level, with the compatibility layer isolated into a separate module. This keeps the core toolchain clean while giving teams a path forward.

    The reality is that enterprise projects cant always keep pace with minimum runtime requirements — some will stay on older Node for years. For those projects, the needs are modest: install dependencies and run scripts. If vpr could cover that, the value of a unified toolchain is preserved even in mixed-version environments.

    Ive been a long-time @antfu/ni user and recently switched entirely to vp — the vision is compelling. But the low-Node pain point is real: it forces fallback to npm for those projects, breaking the muscle memory. Would be great to find a pragmatic solution here.

  9. liangmiQwQ commented on Jun 25, 2026

    @liangmiQwQ
    Collaborator

    I will create a separate issue for styleText's discussion, leaving this issue for your idea.

  10. l246804 commented on Jul 3, 2026

    @l246804
    Author

    Is there any update?

  11. liangmiQwQ commented on Jul 3, 2026

    @liangmiQwQ
    Collaborator

    An alternative worth considering: an explicit opt-in config for legacy Node support at the project level

    For this approach, I think there will be another problem is that we need Node.js to resolve config, means we still need to load Vite+ local JavaScript part. Staticly read config is probably feasible but unstable.

  12. l246804 commented on Jul 3, 2026

    @l246804
    Author

    @liangmiQwQ Regarding config resolution, I'd like to propose: add a static field in package.json (e.g., "vite-plus": { "legacyMode": true }), and have the Rust binary read it directly at startup, without loading any Node.js code. This makes config resolution completely static and avoids module loading errors. Would this be feasible?

  13. liangmiQwQ commented on Jul 3, 2026

    @liangmiQwQ
    Collaborator

    Probably not. Vite+'s philosophy includes putting all config in vite.config.ts, pnpm and other tools in JavaScript ecosystem are also dropping package.json config.

  14. l246804 commented on Jul 3, 2026

    @l246804
    Author

    I vaguely recall OXc can statically scan config.ts fields without launching Node.js. Could we consider having the Rust layer directly parse certain fields (e.g., legacyMode) from vite.config.ts statically? This aligns with Vite+ config philosophy and avoids Node.js. Feasible?

  15. liangmiQwQ commented on Jul 3, 2026

    @liangmiQwQ
    Collaborator

    Statically read config is probably feasible but unstable.

    It is feasible but unstable, if there is like a computed config like config preset or import it can get easily broken. Moreover, I am not sure adding an explicit opt-in config is worth doing, from my personal intuition, it feels a bit strange. Also, thank you for tracing this and offering ideas :)

  16. l246804 commented on Jul 3, 2026

    @l246804
    Author

    Statically read config is probably feasible but unstable.

    It is feasible but unstable, if there is like a computed config like config preset or import it can get easily broken. Moreover, I am not sure adding an explicit opt-in config is worth doing, from my personal intuition, it feels a bit strange. Also, thank you for tracing this and offering ideas :)

    @liangmiQwQ Thanks for your feedback and recognition! I just realized one thing: this issue is essentially about making vpr / vp i work for low-Node projects. But low-Node projects (e.g., Node 14/16) are very unlikely to use Vite — since Vite itself requires a higher Node version — they're probably still on Webpack v4. In that case, they wouldn't even have a vite.config.ts file.

    So if we do need an explicit opt-in config entry, putting it in package.json might be the only universally applicable location. Would you consider this perspective?

  17. liangmiQwQ commented on Jul 3, 2026

    @liangmiQwQ
    Collaborator

    @l246804

    Probably not. Vite+'s philosophy includes putting all config in vite.config.ts, pnpm and other tools in JavaScript ecosystem are also dropping package.json config.

    Moreover, I am not sure adding an explicit opt-in config is worth doing, from my personal intuition, it feels a bit strange.

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

    enhancementto be discussed

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions