Repository navigation
Closed
Labels
Description
Describe the bug
We have a rather large library (~9MB mininized) being converted from webpack to vite. The esm format builds just fine, but umd builds hangs for ~7 minutes. After searching a bit I found the same issue #10900 and doing profiling myself revealed the same offending regex
^(.*?)(\(function\([^)]*\)\s*\{.+?amd.+?function\([^)]*\)\s*\{\s*"use strict";)I can't share the code, but the closest I got is getting a repo in library mode with as much bundled code as possible - though it didn't hang for that long.
Looking at the #7948 that fixed the collision issue, maybe we should find another fix that configures esbuild properly so that no regex replacement is required?
Reproduction
https://stackblitz.com/edit/vitejs-vite-bpuk79?file=index.ts
Steps to reproduce
- Open the stackblitz link
- Run
npm run build - Go to dist and copy the file content to https://regex101.com/
- Fill in the regex as
^(.*?)(\(function\([^)]*\)\s*\{.+?amd.+?function\([^)]*\)\s*\{\s*"use strict";) - Wait for it to show "catastrophic backtracking", click it

- See that it halted after 160k steps. My project's output was halted at 400k steps.

System Info
System:
OS: macOS 13.4.1
CPU: (10) arm64 Apple M1 Pro
Memory: 170.47 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.13.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.19.3 - /usr/local/bin/npm
pnpm: 8.6.2 - /usr/local/bin/pnpm
Browsers:
Chrome: 115.0.5790.170
Safari: 16.5.2
npmPackages:
vite: ^4.4.9 => 4.4.9Used 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.
Reacted by Shein Lin Phyo

Activity
bolt-new-by-stackblitz commentedon Aug 10, 2023
fnlctrl commentedon Aug 10, 2023
I think I've found a minimal reproduction similar to the #7188 issue:
https://stackblitz.com/edit/vitejs-vite-vlp9mq?file=package.json,vite.config.ts&terminal=build
When the
targetrequires helpers (e.g.target: ['chrome66', 'safari11']), and setminify: falseHave the library entry export from another file that uses object spread, and have another expression that uses optional chaining
will cause the output to contain helpers injected to the global scope
However, commenting out either of the lines will prevent the helpers to become global.
Maybe this could help to discovering a better fix to #7188