Skip to content

transform.filter.code regexes with .+ and /s flag cause "Maximum call stack size exceeded" on large files #21696

@JacobSobota

Description

@JacobSobota

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch vite@7.3.1 for the project I'm working on.

The package which had Maximum call stack size exceeded had a JS file 5.7MB, I know it's a lot but It's a very complex thing, which can't be split unfortunately.

Here is the diff that solved my problem:

diff --git a/node_modules/@nuxt/vite-builder/node_modules/vite/dist/node/chunks/config.js b/node_modules/@nuxt/vite-builder/node_modules/vite/dist/node/chunks/config.js
index 2b39a20..2c31471 100644
--- a/node_modules/@nuxt/vite-builder/node_modules/vite/dist/node/chunks/config.js
+++ b/node_modules/@nuxt/vite-builder/node_modules/vite/dist/node/chunks/config.js
@@ -27587,7 +27587,7 @@ async function getWorkerType(raw, clean, i$1) {
 	if (workerOpts.type && (workerOpts.type === "module" || workerOpts.type === "classic")) return workerOpts.type;
 	return "classic";
 }
-const workerImportMetaUrlRE = /new\s+(?:Worker|SharedWorker)\s*\(\s*new\s+URL.+?import\.meta\.url/s;
+const workerImportMetaUrlRE = /import\.meta\.url/;
 function workerImportMetaUrlPlugin(config$2) {
 	const isBuild = config$2.command === "build";
 	let workerResolver;
@@ -27683,7 +27683,7 @@ function assetImportMetaUrlPlugin(config$2) {
 		transform: {
 			filter: {
 				id: { exclude: [exactRegex(preloadHelperId), exactRegex(CLIENT_ENTRY)] },
-				code: /new\s+URL.+import\.meta\.url/s
+				code: /import\.meta\.url/
 			},
 			async handler(code, id) {
 				let s;

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clarity: mediump3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions