polyfills-legacy.js throw error: Cannot assign to read only property 'prototype' of function
See original GitHub issueDescribe the bug
When I use the @vitejs/plugin-legacy plugin to generate polyfills-legacy.js, it throws an error in QQ browser version 9.7:
And this error will cause the later injected Systemjs not to be initialized and executed, resulting in the System object not being found and the page js unable to load and run.
The reason for this is because polyfills-legacy.js tries to assign undefined to Array.prototype[Symbol.iterator].prototype, but in QQ browser version 9.7, this value is not writable, and the generation of polyfills-legacy chunk It is built by vite using es build, which makes the chunk enter strict mode by default, resulting in an error.
This issue should cause errors in all browsers with this feature. Although currently I only encountered it in the 9.7 version of the QQ browser. At present, I solved it by adding a polyfillUseStrict parameter to the local plugin-legacy plugin through patch-package to control the polyfill chunk not to use strict mode. I don’t know if there are other better solutions or if I am using it wrong.
Reproduction
https://github.com/daoerche/polyfills-legacy-error-demo
System Info
System:
OS: macOS 11.4
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 1.58 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
Browsers:
Chrome: 95.0.4638.69
Firefox: 98.0.1
Safari: 14.1.1
npmPackages:
@vitejs/plugin-legacy: ^1.8.2 => 1.8.2
vite: ^2.9.5 => 2.9.5
Used Package Manager
npm
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 https://github.com/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.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
core-js Added a workaround in 3.22.7. Thanks~
ok~