stripLiteral
for import.meta
processing may fail while processing large literal (~10MB)
#15759
Closed
7 tasks done
Labels
duplicate
This issue or pull request already exists
Describe the bug
Related: #8054
In the
asset-import-meta-url
plugin, I'm utilizingstrip-literal
to sanitize input code.vite/packages/vite/src/node/plugins/assetImportMetaUrl.ts
Lines 53 to 59 in 734a9e3
However, I've identified a potential issue with this approach. The implementation of
jsToken
, whichstrip-literal
depends on, is based on regular expressions and may encounter arecursion size exceeded
error if it comes across large string literals. This seems to be a problem originating from V8.There is currently an open issue and a corresponding PR in the upstream repository aiming to provide a workaround for this issue: lydell/js-tokens#43. However, this solution is yet to be merged and appears unstable, potentially still failing in certain edge cases.
As a potential solution, I'm proposing to handle this exception and, in the event of a stripping failure, use the input string as it was originally. I believe this could effectively mitigate the issue until a more stable solution is implemented in the
jsToken
library. I would appreciate your thoughts and suggestions on this proposal.Reproduction
https://stackblitz.com/edit/vitejs-vite-cruckz?file=main.js
Steps to reproduce
Write a JS in this form:
Import this file in Vite managed site file, it will fail with
RangeError
.System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.18.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.2.3 - /usr/local/bin/npm pnpm: 8.14.0 - /usr/local/bin/pnpm npmPackages: vite: ^5.0.12 => 5.0.12
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: