{"record":{"id":"c7a50e0962b29fe2","repo":"microsoft/aspire","slug":"aspire-remote-apphost-token-environment-variable-is-not-set","errorCode":null,"errorMessage":"ASPIRE_REMOTE_APPHOST_TOKEN environment variable is not set.","messagePattern":"ASPIRE_REMOTE_APPHOST_TOKEN environment variable is not set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.TypeScript/Resources/transport.mts","lineNumber":965,"sourceCode":"                        if (!callback) {\n                            throw new Error(`Callback not found: ${callbackId}`);\n                        }\n                        try {\n                            // The registered wrapper handles arg unpacking and handle wrapping\n                            // Pass this client so handles can be wrapped with typed wrapper classes\n                            return await Promise.resolve(callback(args, this));\n                        } catch (error) {\n                            const message = error instanceof Error ? error.message : String(error);\n                            throw new Error(`Callback execution failed: ${message}`);\n                        }\n                    });\n\n                    socket.on('error', onConnectedSocketError);\n                    socket.on('close', onConnectedSocketClose);\n\n                    const authToken = process.env.ASPIRE_REMOTE_APPHOST_TOKEN;\n                    if (!authToken) {\n                        throw new Error('ASPIRE_REMOTE_APPHOST_TOKEN environment variable is not set.');\n                    }\n                    this.connection.listen();\n                    const authenticated = await this.connection.sendRequest<boolean>('authenticate', authToken);\n                    if (!authenticated) {\n                        throw new Error('Failed to authenticate to the AppHost server.');\n                    }\n\n                    connectedClients.add(this);\n                    this._connectPromise = null;\n                    settled = true;\n\n                    resolve();\n                } catch (error) {\n                    failConnect(error instanceof Error ? error : new Error(String(error)));\n                }\n            };\n\n            const timeout = setTimeout(() => {","sourceCodeStart":947,"sourceCodeEnd":983,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.TypeScript/Resources/transport.mts#L947-L983","documentation":"During AspireClient.connect, before authenticating, the client reads ASPIRE_REMOTE_APPHOST_TOKEN from the environment. If it is missing, connect throws immediately instead of attempting an unauthenticated JSON-RPC handshake.","triggerScenarios":"Calling connect() (which opens the socket and starts the authenticate handshake) in a process where the ASPIRE_REMOTE_APPHOST_TOKEN environment variable was never set.","commonSituations":"Running the generated client outside the Aspire launch environment (plain node script, IDE run without env vars); CI job without the secret injected; token set only in one shell profile but the app launched from another; typo in variable name.","solutions":["Set ASPIRE_REMOTE_APPHOST_TOKEN before starting the process, e.g. `ASPIRE_REMOTE_APPHOST_TOKEN=<token> node app.mts`.","Run the client through the Aspire AppHost / launch environment that injects the token automatically.","Add the token to your .env / CI secret configuration and ensure it is loaded (dotenv, workflow env mapping).","Verify the exact spelling ASPIRE_REMOTE_APPHOST_TOKEN (check `printenv | grep ASPIRE`)."],"exampleFix":"// before\nconst client = new AspireClient();\nawait client.connect(); // throws: token missing\n\n// after\n// shell: export ASPIRE_REMOTE_APPHOST_TOKEN=<token>\nif (!process.env.ASPIRE_REMOTE_APPHOST_TOKEN) {\n  throw new Error('Set ASPIRE_REMOTE_APPHOST_TOKEN before connecting');\n}\nconst client = new AspireClient();\nawait client.connect();","handlingStrategy":"validation","validationCode":"if (!process.env.ASPIRE_REMOTE_APPHOST_TOKEN) {\n  throw new Error('Set ASPIRE_REMOTE_APPHOST_TOKEN before calling connect()');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (err) {\n  if (String(err.message).includes('ASPIRE_REMOTE_APPHOST_TOKEN')) {\n    console.error('Missing token: run via the Aspire AppHost or export the variable');\n  }\n  throw err;\n}","preventionTips":["Launch the client through the Aspire environment that injects the token.","Check for the variable at process start with a fast-fail guard.","In CI, wire the token as a secret env mapping.","Grep for typos: ASPIRE_REMOTE_APPHOST_TOKEN exactly."],"tags":["environment","authentication","configuration","typescript"],"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"}