question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

polyfills-legacy.js throw error: Cannot assign to read only property 'prototype' of function

See original GitHub issue

Describe 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: image

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. image

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. image

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. image

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
daoerchecommented, May 24, 2022

core-js Added a workaround in 3.22.7. Thanks~

0reactions
daoerchecommented, May 24, 2022

ok~

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot assign to read only property 'prototype' of function ...
Any ideas what could be causing this? javascript · vue.js · html-framework-7 · Share.
Read more >
The way too handle readonly properties in the prototype.
First of all here's the code that made me thought if this: function Constructor( ) { } Constructor.prototype.property = 'prototype'; var object =...
Read more >
Function.prototype.name - JavaScript - MDN Web Docs
It has no semantic significance to the language itself. The name property is read-only and cannot be changed by the assignment operator:.
Read more >
typescript cannot assign read only propertie - You.com
Upgrading to typescript 4.1 which apparently introduced React 17 JSX Factories causes the error Cannot assign to read only property 'jsx' of object...
Read more >
What Happens When You Freeze a Prototype in JavaScript
In JavaScript, objects are dynamic collections of properties with a ... //Cannot assign to read only property 'increment' of object '#'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found