{"record":{"id":"d238a82d44612219","repo":"microsoft/aspire","slug":"error-applying-aspire-vite-configuration-falling-back-to","errorCode":null,"errorMessage":"Error applying Aspire Vite configuration. Falling back to original configuration without Aspire HTTPS modifications.","messagePattern":"Error applying Aspire Vite configuration\\. Falling back to original configuration without Aspire HTTPS modifications\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs","lineNumber":113,"sourceCode":"    })\n\n    let finalConfig = config\n    try {\n        if (typeof config === 'function') {\n            finalConfig = defineConfig((cfg) => {\n                let innerConfig = config(cfg)\n\n                return wrapConfig(innerConfig)\n            });\n        } else if (typeof config === 'object' && config !== null) {\n            let innerConfig = config\n            finalConfig = defineConfig(wrapConfig(innerConfig))\n        } else {\n            console.warn('Unexpected Vite config format. Falling back to original configuration without Aspire HTTPS modifications.')\n            finalConfig = config\n        }\n    } catch {\n        console.warn('Error applying Aspire Vite configuration. Falling back to original configuration without Aspire HTTPS modifications.')\n        finalConfig = config\n    }\n\n    export default finalConfig\n    \"\"\";\n\n    /// <summary>\n    /// Adds a node application to the application model. Node should be available on the PATH.\n    /// </summary>\n    /// <param name=\"builder\">The <see cref=\"IDistributedApplicationBuilder\"/> to add the resource to.</param>\n    /// <param name=\"name\">The name of the resource.</param>\n    /// <param name=\"appDirectory\">The path to the directory containing the node application.</param>\n    /// <param name=\"scriptPath\">The path to the script relative to the app directory to run.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    /// <ats-returns>The resource builder.</ats-returns>\n    /// <remarks>\n    /// This method executes a Node script directly using <c>node script.js</c>. If you want to use a package manager\n    /// you can add one and configure the install and run scripts using the provided extension methods.","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L95-L131","documentation":"This is the catch-all path of Aspire's vite.config HTTPS-injection script: if evaluating or wrapping the existing vite configuration throws for any reason, the script logs this console.warn and exports the original configuration unmodified. The app continues to run but without the Aspire-applied HTTPS/dev-certificate settings.","triggerScenarios":"Any exception thrown while evaluating vite.config content during the rewrite (syntax errors in the config file, missing imports that execute at load time, plugin code throwing at module init), triggering the catch block that warns and falls back.","commonSituations":"vite.config.ts/js with top-level code that throws when executed outside Vite (missing env vars, absent node_modules, importing packages not installed); corrupted or partially written config; using syntax the evaluator cannot parse.","solutions":["Run the dev server (or 'vite --version') directly to surface the underlying exception being swallowed by this catch — fix that root error in vite.config.","Install missing dependencies referenced at the top level of vite.config (imports execute during Aspire's evaluation).","Simplify vite.config so it can be evaluated standalone (avoid throwing side effects at module scope), or guard them with try/catch.","If HTTPS is managed manually, confirm the dev server's URLs match the endpoints Aspire exposes, since the fallback skips Aspire's HTTPS modifications."],"exampleFix":"// before: side effect that throws at module scope\nconst cert = fs.readFileSync(process.env.CERT_PATH); // throws if unset\nexport default defineConfig({ server: { https: { key: cert } } });\n// after: guarded side effect\nconst cert = process.env.CERT_PATH ? fs.readFileSync(process.env.CERT_PATH) : undefined;\nexport default defineConfig({ server: cert ? { https: { key: cert } } : {} });","handlingStrategy":"validation","validationCode":"// Ensure vite.config can be evaluated standalone before the AppHost touches it.\ntry {\n  await import('./vite.config.ts');\n} catch (e) {\n  console.error('vite.config throws on evaluation; fix before Aspire applies HTTPS config:', e);\n}","typeGuard":null,"tryCatchPattern":"// The injector swallows the real error; surface it yourself:\ntry {\n  const cfg = await import(/* @vite-ignore */ viteConfigPath);\n} catch (e) {\n  throw new Error(`vite.config evaluation failed (Aspire will fall back without HTTPS config): ${e.message}`, { cause: e });\n}","preventionTips":["Keep vite.config free of throwing module-scope side effects (env reads, fs access) — guard them.","Install all dependencies imported by vite.config so top-level evaluation succeeds.","Run 'vite' directly once after edits to catch config errors early."],"tags":["vite","javascript","config","fallback"],"backgroundTag":"module-init-failed","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}