diff --git a/packages/cypress/src/plugins/plugin.ts b/packages/cypress/src/plugins/plugin.ts index 14f60ebeb1..0a97ae00a1 100644 --- a/packages/cypress/src/plugins/plugin.ts +++ b/packages/cypress/src/plugins/plugin.ts @@ -263,15 +263,15 @@ function getCypressConfig( if (tsConfigPath) { const unregisterTsProject = registerTsProject(tsConfigPath); try { - module = require(resolvedPath); + module = load(resolvedPath); } finally { unregisterTsProject(); } } else { - module = require(resolvedPath); + module = load(resolvedPath); } } else { - module = require(resolvedPath); + module = load(resolvedPath); } return module.default ?? module; } @@ -297,3 +297,18 @@ function getInputs( }, ]; } + +/** + * Load the module after ensuring that the require cache is cleared. + */ +function load(path: string): any { + // Clear cache if the path is in the cache + if (require.cache[path]) { + for (const k of Object.keys(require.cache)) { + delete require.cache[k]; + } + } + + // Then require + return require(path); +}