diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 338ffd562f86b3..c13e5ed6b9d33c 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -95,7 +95,21 @@ function preload( // in that case fallback to getAttribute const cspNonce = cspNonceMeta?.nonce || cspNonceMeta?.getAttribute('nonce') - promise = Promise.allSettled( + // Promise.allSettled is not supported by Chrome 64-75, Firefox 67-70, Safari 11.1-12.1 + function allSettled( + promises: Array>, + ): Promise[]> { + return Promise.all( + promises.map((p) => + Promise.resolve(p).then( + (value: T) => ({ status: 'fulfilled' as const, value }), + (reason: unknown) => ({ status: 'rejected' as const, reason }), + ), + ), + ) + } + + promise = allSettled( deps.map((dep) => { // @ts-expect-error assetsURL is declared before preload.toString() dep = assetsURL(dep, importerUrl) diff --git a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts index cf17de4ba2bb15..510b64d65921cb 100644 --- a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts +++ b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts @@ -143,7 +143,7 @@ describe.runIf(isBuild)('build tests', () => { { "debugId": "00000000-0000-0000-0000-000000000000", "ignoreList": [], - "mappings": ";+8BAAA,OAAO,2BAAuB,0BAE9B,QAAQ,IAAI,uBAAuB", + "mappings": ";4kCAAA,OAAO,2BAAuB,0BAE9B,QAAQ,IAAI,uBAAuB", "sources": [ "../../after-preload-dynamic.js", ],