Skip to content

bug: vite-plus@0.2.1 crashes on Node < 20.12 with "node:util has no export named styleText" before engine check #1909

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/vite-plus@0.2.1_vite@8.0.16/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions