From 91fac1ca1c31dfdd7e0b33186ea23b5e79a1b4cf Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Wed, 22 Feb 2023 16:33:15 +0800 Subject: [PATCH] fix(import-analysis): improve error for jsx to not be preserve in tsconfig (#12018) --- packages/vite/src/node/plugins/importAnalysis.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 3d3f81564a30e7..75d0b57f0188f6 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -197,12 +197,15 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { ;[imports, exports] = parseImports(source) } catch (e: any) { const isVue = importer.endsWith('.vue') + const isJsx = importer.endsWith('.jsx') || importer.endsWith('.tsx') const maybeJSX = !isVue && isJSRequest(importer) const msg = isVue ? `Install @vitejs/plugin-vue to handle .vue files.` : maybeJSX - ? `If you are using JSX, make sure to name the file with the .jsx or .tsx extension.` + ? isJsx + ? `If you use tsconfig.json, make sure to not set jsx to preserve.` + : `If you are using JSX, make sure to name the file with the .jsx or .tsx extension.` : `You may need to install appropriate plugins to handle the ${path.extname( importer, )} file format, or if it's an asset, add "**/*${path.extname(