From 556ec1013221d38d086158b0a20b50083475b83b Mon Sep 17 00:00:00 2001 From: Svilen Ivanov Date: Wed, 9 Mar 2022 09:24:53 +0200 Subject: [PATCH 1/2] Can't use `regenerator-runtime` with CSP Can't use `regenerator-runtime` with CSP on old browsers (e.g. Chrome 38, IE 11). Caused by lack of `globalThis` and resorting to dynamic eval. Update the documentation for giving other users heads up. --- packages/plugin-legacy/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/plugin-legacy/README.md b/packages/plugin-legacy/README.md index c56b769061e267..1e0a05a36aa2db 100644 --- a/packages/plugin-legacy/README.md +++ b/packages/plugin-legacy/README.md @@ -173,6 +173,8 @@ These values (without the `sha256-` prefix) can also be retrieved via const { cspHashes } = require('@vitejs/plugin-legacy') ``` +The `regenerator-runtime` polyfill attempts to use `globalThis` object to register itself. If `globalThis` is not available (it is [fairly new](https://caniuse.com/?search=globalThis) and not widely supported, including IE 11), it attempts to perform dynamic `Function(...)` call which violates the CSP. To avoid dynamic `eval` in the absence of `globalThis` consider adding `core-js/proposals/global-this` to `additionalLegacyPolyfills` to define it. + ## References - [Vue CLI modern mode](https://cli.vuejs.org/guide/browser-compatibility.html#modern-mode) From 09dfc829e4c5950d7139df4dcf1b4b1a2bbb40e5 Mon Sep 17 00:00:00 2001 From: Svilen Ivanov Date: Wed, 9 Mar 2022 22:41:27 +0200 Subject: [PATCH 2/2] Update packages/plugin-legacy/README.md Co-authored-by: Bjorn Lu --- packages/plugin-legacy/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-legacy/README.md b/packages/plugin-legacy/README.md index 1e0a05a36aa2db..b5bf572e53fa2c 100644 --- a/packages/plugin-legacy/README.md +++ b/packages/plugin-legacy/README.md @@ -173,7 +173,7 @@ These values (without the `sha256-` prefix) can also be retrieved via const { cspHashes } = require('@vitejs/plugin-legacy') ``` -The `regenerator-runtime` polyfill attempts to use `globalThis` object to register itself. If `globalThis` is not available (it is [fairly new](https://caniuse.com/?search=globalThis) and not widely supported, including IE 11), it attempts to perform dynamic `Function(...)` call which violates the CSP. To avoid dynamic `eval` in the absence of `globalThis` consider adding `core-js/proposals/global-this` to `additionalLegacyPolyfills` to define it. +When using the `regenerator-runtime` polyfill, it will attempt to use the `globalThis` object to register itself. If `globalThis` is not available (it is [fairly new](https://caniuse.com/?search=globalThis) and not widely supported, including IE 11), it attempts to perform dynamic `Function(...)` call which violates the CSP. To avoid dynamic `eval` in the absence of `globalThis` consider adding `core-js/proposals/global-this` to `additionalLegacyPolyfills` to define it. ## References