From 9241d0895b37c658a2dccfd961958c0c5238a49b Mon Sep 17 00:00:00 2001 From: Wu Rui Date: Thu, 2 Feb 2023 21:08:36 +0800 Subject: [PATCH] fix(legacy): fix browserslist import, close https://github.com/vitejs/vite/issues/11898 (#11899) --- packages/plugin-legacy/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index d9a6d49f1cd3e1..acb318db988591 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -23,7 +23,7 @@ import type { types as BabelTypes, } from '@babel/core' import colors from 'picocolors' -import { loadConfig as browserslistLoadConfig } from 'browserslist' +import browserslist from 'browserslist' import type { Options } from './types' import { detectModernBrowserCode, @@ -45,6 +45,10 @@ async function loadBabel() { return babel } +// The requested module 'browserslist' is a CommonJS module +// which may not support all module.exports as named exports +const { loadConfig: browserslistLoadConfig } = browserslist + // Duplicated from build.ts in Vite Core, at least while the feature is experimental // We should later expose this helper for other plugins to use function toOutputFilePathInHtml(