You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Vite's build function via Gulp throws ReferenceError: require2 is not defined during LESS build
I'm building a library by calling Vite's build function programmatically inside a Gulp task.
During the build process, when compiling LESS files, the build throws the following exception: ReferenceError: require2 is not defined
🔍 Debugging
By debugging, I located the problematic code around this snippet inside Vite’s internal modules:
Inside the constructor of WorkerWithFallback, I logged the function passed in by calling fn.toString().
To my surprise, the logged function source already has require replaced by require2:
Questions
Why is the original require being transformed to require2 at runtime inside Vite's internal code?
Where is require2 defined or supposed to be defined?
How can I fix this error so that the build completes successfully when invoked via Gulp?
Is this caused by the way Vite bundles its internal worker code?
Is there a recommended way to use Vite's build function programmatically without hitting this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Using Vite's build function via Gulp throws
ReferenceError: require2 is not defined
during LESS buildI'm building a library by calling Vite's
build
function programmatically inside a Gulp task.During the build process, when compiling LESS files, the build throws the following exception:
ReferenceError: require2 is not defined
🔍 Debugging
By debugging, I located the problematic code around this snippet inside Vite’s internal modules:
Inside the constructor of WorkerWithFallback, I logged the function passed in by calling
fn.toString()
.To my surprise, the logged function source already has
require
replaced byrequire2
:Questions
Why is the original
require
being transformed torequire2
at runtime inside Vite's internal code?Where is
require2
defined or supposed to be defined?How can I fix this error so that the build completes successfully when invoked via Gulp?
Is this caused by the way Vite bundles its internal worker code?
Is there a recommended way to use Vite's build function programmatically without hitting this?
Environment
Vite version: 7.0.6
Node.js version: (please specify your version)
Gulp version: 4.x
OS: (please specify your OS)
Beta Was this translation helpful? Give feedback.
All reactions