{"record":{"id":"96f4ed56cd4894c0","repo":"microsoft/aspire","slug":"remote-app-host-socket-path-environment-variable-not-set-run-96f4ed","errorCode":null,"errorMessage":"REMOTE_APP_HOST_SOCKET_PATH environment variable not set. Run this application using `aspire run`.","messagePattern":"REMOTE_APP_HOST_SOCKET_PATH environment variable not set\\. Run this application using `aspire run`\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.TypeScript/AtsTypeScriptCodeGenerator.cs","lineNumber":1942,"sourceCode":"    }\n\n    private void GenerateConnectionHelper()\n    {\n        var builderHandle = TypeScriptApiProjector.GetHandleTypeName(AtsConstants.BuilderTypeId);\n\n        WriteLine($$\"\"\"\n            // ============================================================================\n            // Connection Helper\n            // ============================================================================\n\n            /**\n             * Creates and connects to the Aspire AppHost.\n             * Reads connection info from environment variables set by `aspire run`.\n             */\n            export async function connect(): Promise<AspireClientRpc> {\n                const socketPath = process.env.REMOTE_APP_HOST_SOCKET_PATH;\n                if (!socketPath) {\n                    throw new Error(\n                        'REMOTE_APP_HOST_SOCKET_PATH environment variable not set. ' +\n                        'Run this application using `aspire run`.'\n                    );\n                }\n\n                const client = new AspireClient(socketPath);\n                await client.connect();\n\n                // Exit the process if the server connection is lost\n                client.onDisconnect(() => {\n                    console.error('Connection to AppHost lost. Exiting...');\n                    process.exit(1);\n                });\n\n                return client;\n            }\n\n            /**","sourceCodeStart":1924,"sourceCodeEnd":1960,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.TypeScript/AtsTypeScriptCodeGenerator.cs#L1924-L1960","documentation":"This error is thrown by the TypeScript client code generated by the ATS TypeScript code generator. The generated `connect()` function reads REMOTE_APP_HOST_SOCKET_PATH from process.env to find the AppHost's Unix domain socket, because that path is only provided by `aspire run`. If the variable is unset or empty, the function throws an Error immediately rather than failing with an obscure socket connection error later.","triggerScenarios":"Calling the generated `connect()` (typically from the generated app's startup code) in a Node process where process.env.REMOTE_APP_HOST_SOCKET_PATH is undefined or an empty string.","commonSituations":"Starting the generated TypeScript app with `node dist/index.js`, npm, or an IDE debugger instead of `aspire run`; running inside Docker/CI without exporting the variable; using a terminal not launched through the AppHost so the connection environment was never injected.","solutions":["Run the application with `aspire run`, which sets REMOTE_APP_HOST_SOCKET_PATH and the auth token automatically.","For manual runs, export REMOTE_APP_HOST_SOCKET_PATH to the current AppHost socket path before starting Node (get the value from the running `aspire run` session).","In containers/CI, pass the variable through (e.g. docker run -e REMOTE_APP_HOST_SOCKET_PATH=... -v <socket>:/path/to/socket).","Check for dotenv or process-env sanitization in your app that may be wiping the injected environment variables."],"exampleFix":"// before\nnode dist/index.js   // Error: REMOTE_APP_HOST_SOCKET_PATH not set\n\n// after\naspire run   // or: REMOTE_APP_HOST_SOCKET_PATH=/tmp/aspire/apphost.sock node dist/index.js","handlingStrategy":"validation","validationCode":"if (!process.env.REMOTE_APP_HOST_SOCKET_PATH) {\n  console.error(\"Launch via 'aspire run' or set REMOTE_APP_HOST_SOCKET_PATH\");\n  process.exit(1);\n}","typeGuard":"function hasSocketPath(env) { return typeof env.REMOTE_APP_HOST_SOCKET_PATH === 'string' && env.REMOTE_APP_HOST_SOCKET_PATH.length > 0; }","tryCatchPattern":"try {\n  const client = await connect();\n} catch (err) {\n  if (String(err.message).includes('REMOTE_APP_HOST_SOCKET_PATH')) {\n    // print launch instructions or exit gracefully\n  }\n}","preventionTips":["Launch generated apps via `aspire run`, not node/npm/IDE runners.","Pass the env var explicitly into containers (-e) and CI jobs.","Guard against dotenv configs overwriting/clearing injected env vars."],"tags":["typescript","environment","apphost","code-generation"],"backgroundTag":"missing-env-var","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"}