-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Labels
Description
Describe the bug
When running the Vite build() API inside a script executed via tsx-cli, and the project contains .less files, the build process throws the following error:
ReferenceError: require2 is not defined
at eval (eval at FakeWorker (C:\Users\I2288773\Workspace\MyPledge\build-test\node_modules\.pnpm\rolldown-vite@7.1.1_@types+_483053de22fda570198728257ed16612\node_modules\rolldown-vite\dist\node\chunks\dep-BBmQs1ZR.js:49:835), <anonymous>:5:32)
at eval (eval at FakeWorker (C:\Users\I2288773\Workspace\MyPledge\build-test\node_modules\.pnpm\rolldown-vite@7.1.1_@types+_483053de22fda570198728257ed16612\node_modules\rolldown-vite\dist\node\chunks\dep-BBmQs1ZR.js:49:835), <anonymous>:5:1274)
Reproduction
https://stackblitz.com/edit/vitejs-vite-ir8ahelm?file=build.ts
Steps to reproduce
Use tsx-cli to execute a script that calls Vite's build() API programmatically.
Ensure the project includes .less files.
Run the build script via tsx (e.g., tsx build.ts).
Encounter the require2 is not defined error.
System Info
"tsx": "^4.20.3",
"less": "^4.4.0",
"vite": "^7.1.2"Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.