New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when manually including vite/modulepreload-polyfill #4786
Comments
I've got the exactly same error when importing vite/modulepreload-polyfill with backend integration. |
Same here, any solutions appreciated |
Here is my workaround. |
Unfortunately in TypeScript, the workaround throws the error: My workaround was to copy the polyfill function at https://github.com/vitejs/vite/blob/cb75dbd4a2b1c56e2a7aeaf1625818a4d1865f00/packages/vite/src/node/plugins/modulePreloadPolyfill.ts and run it in its own file. |
If you have eslint rule /* eslint-disable import/first */
if (import.meta.env.MODE !== 'development') {
// @ts-expect-error
import('vite/modulepreload-polyfill')
}
// other imports... |
How do you turn the dynamic into a static import? For those who already changed manualChunks from it's default value then |
also if using it's will generate two chunk, modulepreload-polyfill-legacy.********.js : System.register([],(function(){"use strict";return{execute:function(){}}}));
!function(){const e=document.createElement("link").relList;if(!(e&&e.supports&&e.supports("modulepreload"))){for(const e of document.querySelectorAll('link[rel="modulepreload"]'))r(e);new MutationObserver((e=>{for(const o of e)if("childList"===o.type)for(const e of o.addedNodes)"LINK"===e.tagName&&"modulepreload"===e.rel&&r(e)})).observe(document,{childList:!0,subtree:!0})}function r(e){if(e.ep)return;e.ep=!0;const r=function(e){const r={};return e.integrity&&(r.integrity=e.integrity),e.referrerpolicy&&(r.referrerPolicy=e.referrerpolicy),"use-credentials"===e.crossorigin?r.credentials="include":"anonymous"===e.crossorigin?r.credentials="omit":r.credentials="same-origin",r}(e);fetch(e.href,r)}}(); |
If you are running tsc against this, the |
Describe the bug
When manually including
vite/modulepreload-polyfill
as per backend integration an error is thrown in the browser when runningvite serve
.I'm guessing because
__VITE_IS_MODERN__
is replaced during build and during "normal" Vite usage the polyfill is only added to the output during build, but with a backend integration the polyfill is present during dev and build.Reproduction
Issue can be replicated outside of a backend integration by:
vite/modulepreload-polyfill
into an entry filevite serve
, visiting the dev server and opening the browser dev toolsThis yields the same result as I'm seeing with my backend setup.
https://github.com/rynpsc/vite-modulepreload-polyfill
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: