From 38fec9ca776bfd29c7b984871471da3860f842a1 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 8 Aug 2023 12:24:05 -0700 Subject: [PATCH] feat(testing): Vite 5 compatibility for Cypress (#18535) --- packages/cypress/src/plugins/preprocessor-vite.ts | 4 +++- packages/react/plugins/component-testing/index.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/cypress/src/plugins/preprocessor-vite.ts b/packages/cypress/src/plugins/preprocessor-vite.ts index f5d9fa5ca2ed4..4cacbfcfc6780 100644 --- a/packages/cypress/src/plugins/preprocessor-vite.ts +++ b/packages/cypress/src/plugins/preprocessor-vite.ts @@ -74,7 +74,9 @@ function vitePreprocessor(userConfigPath?: string): CypressPreprocessor { cache.set(filePath, outputPath); - const { build } = require('vite'); + const { build } = await (Function('return import("vite")')() as Promise< + typeof import('vite') + >); const watcher = (await build({ configFile: userConfigPath, diff --git a/packages/react/plugins/component-testing/index.ts b/packages/react/plugins/component-testing/index.ts index 82ee45f60fd62..a58b0fdd9f614 100644 --- a/packages/react/plugins/component-testing/index.ts +++ b/packages/react/plugins/component-testing/index.ts @@ -84,7 +84,9 @@ export function nxComponentTestingPreset( const viteConfigPath = findViteConfig(normalizedProjectRootPath); const { mergeConfig, loadConfigFromFile, searchForWorkspaceRoot } = - await import('vite'); + await (Function('return import("vite")')() as Promise< + typeof import('vite') + >); const resolved = await loadConfigFromFile( {