Skip to content

ReferenceError: require2 is not defined when building project with less using vite build() via tsx-cli #20600

@MyPledge

Description

@MyPledge

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions