Repository navigation
bug: [email protected] crashes on Node < 20.12 with "node:util has no export named styleText" before engine check #1909
Description
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:
- Avoid the static
import { styleText } from "node:util"in any module that can be loaded before the engine check (in particularterminal-*.js, which the CLI bootstrap pulls in eagerly). A smallpc-style fallback or a dynamic import gated onprocess.versions.node >= 20.12would let the runner reach thevprsoft-fallback path; or - 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:
- In a directory with
.node-versioncontaining14.15.0(or usevp env use 14.15.0). vpr dev(or anyvpr <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
- vpr should not hard-fail on incompatible Node version — fall back like @antfu/ni #1875 —
vprshould soft-fallback on incompatible Node versions. This issue is what blocks that fallback from ever being reached on 0.2.1, because the failure happens during ESM instantiation ofterminal-uTv0ZaMr.js, prior to any version-guard logic.
Validations
- Read the Contributing Guidelines.
- Checked existing issues; vpr should not hard-fail on incompatible Node version — fall back like @antfu/ni #1875 is related but distinct (engine guard vs. unconditional
node:utilnamed import). - This is a Vite+ issue (the offending import lives in the published
vite-pluspackage). - Reproduction is minimal (any low-Node project +
vpr <script>).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fengmk2 commentedon Jun 22, 2026
https://github.com/voidzero-dev/vite-plus/blob/main/packages/cli/package.json#L439 We have currently raised the minimum supported node version to
20.19.0.l246804 commentedon Jun 22, 2026
I understand bumping engines to
^20.19.0— Vite+ core needn't support Node 14. But I'd like to suggest another angle: whenvprdetects 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 tovpronly.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
vpras a script runner (#1875) is one muscle memory across every repo; if low-Node repos force a fallback tonr/npm run, that universality is lost.Sketch
Version check in the Rust trampoline (no Node module loader involved):
Benefits
styleText-style errors disappearvpr—vp dev/vp buildetc. keep the engines guardfengmk2 commentedon Jun 22, 2026
Good suggestion. Are you willing to try to implement it?
One relatively challenging thing is how to continuously ensure that the
vprcommand will not be compromised by subsequent new features. It is necessary to consider adding continuous validation test cases.l246804 commentedon Jun 22, 2026
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.
l246804 commentedon Jun 23, 2026
Adding to the shim scope: on low Node,
vp i(project install) breaks the same way asvpr, and worse — it leavesdevEngines.packageManager = [email protected]inpackage.jsonand routes everynpmcall to an npm version incompatible with the active Node (npm 11 needs Node ≥20.17; under Node 14 it throwsCannot find module 'node:path'). So not only isvp iunusable on low Node, it also breaks manualnpm i/npm run devafterward.Filed as a separate, independently-reproducible bug: #1916. The passthrough/shim idea here should cover both
vprandvp i— at minimum, on unsupported Node, forward to the Node-bundled package manager instead of loading Vite+ JS or pinning an incompatible npm.feat(passthrough): add low-Node passthrough for eligible commands
liangmiQwQ commentedon Jun 24, 2026
I am a bit worried about whether it is a long-term, sustainable plan.
vp runrelies on Vite Task, delegating to the underlying package manager makesvp runhave 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
picocolorsrather thannode:util#styleText.l246804 commentedon Jun 25, 2026
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#styleTextwith polyfills such aspicocolorsacross 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
vprcould cover that, the value of a unified toolchain is preserved even in mixed-version environments.Ive been a long-time
@antfu/niuser and recently switched entirely tovp— the vision is compelling. But the low-Node pain point is real: it forces fallback tonpmfor those projects, breaking the muscle memory. Would be great to find a pragmatic solution here.liangmiQwQ commentedon Jun 25, 2026
I will create a separate issue for
styleText's discussion, leaving this issue for your idea.l246804 commentedon Jul 3, 2026
Is there any update?
liangmiQwQ commentedon Jul 3, 2026
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.
l246804 commentedon Jul 3, 2026
@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?
liangmiQwQ commentedon Jul 3, 2026
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.l246804 commentedon Jul 3, 2026
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?
liangmiQwQ commentedon Jul 3, 2026
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 :)
l246804 commentedon Jul 3, 2026
@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?
liangmiQwQ commentedon Jul 3, 2026
@l246804