{"record":{"id":"4edcd655e4dc409d","repo":"firecrawl/open-lovable","slug":"failed-to-install-packages-response-statustext","errorCode":null,"errorMessage":"Failed to install packages: ${response.statusText}","messagePattern":"Failed to install packages: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/generation/page.tsx","lineNumber":438,"sourceCode":"      textarea.focus();\n    }\n  };\n  \n  const installPackages = async (packages: string[]) => {\n    if (!sandboxData) {\n      addChatMessage('No active sandbox. Create a sandbox first!', 'system');\n      return;\n    }\n    \n    try {\n      const response = await fetch('/api/install-packages', {\n        method: 'POST',\n        headers: { 'Content-Type': 'application/json' },\n        body: JSON.stringify({ packages })\n      });\n      \n      if (!response.ok) {\n        throw new Error(`Failed to install packages: ${response.statusText}`);\n      }\n      \n      const reader = response.body?.getReader();\n      const decoder = new TextDecoder();\n      \n      while (reader) {\n        const { done, value } = await reader.read();\n        if (done) break;\n        \n        const chunk = decoder.decode(value);\n        const lines = chunk.split('\\n');\n        \n        for (const line of lines) {\n          if (line.startsWith('data: ')) {\n            try {\n              const data = JSON.parse(line.slice(6));\n              \n              switch (data.type) {","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/firecrawl/open-lovable/blob/69bd93bae7a9c97ef989eb70aabe6797fb3dac89/app/generation/page.tsx#L420-L456","documentation":"The client in app/generation/page.tsx POSTs a package list to the install API and, when the fetch response is not ok, throws this Error containing response.statusText. It surfaces HTTP-level failures (4xx/5xx) from the server-side install endpoint, not npm errors themselves.","triggerScenarios":"The /api install endpoint returns non-OK: sandbox missing/not provisioned server-side, Vercel credentials invalid, request rate-limited or timed out (504), package name rejected, or the route crashed (500).","commonSituations":"Sandbox expired server-side between page load and install; deployment missing VERCEL_TOKEN env vars so the API can't reach the sandbox; oversized/invalid package list; Vercel function timeout during a large npm install.","solutions":["Check the server route logs to find the underlying cause behind the statusText","Verify Vercel sandbox credentials (VERCEL_TOKEN, VERCEL_TEAM_ID, VERCEL_PROJECT_ID or OIDC token) in the deployment environment","Recreate/ensure the sandbox before calling the install endpoint, and retry transient 5xx","Validate/sanitize the packages list client-side and surface the HTTP status in the UI"],"exampleFix":"// before\nif (!response.ok) {\n  throw new Error(`Failed to install packages: ${response.statusText}`);\n}\n// after\nif (!response.ok) {\n  const body = await response.text().catch(() => '');\n  if (response.status >= 500) { await recreateSandbox(); return retryInstall(packages); }\n  throw new Error(`Failed to install packages: ${response.status} ${response.statusText} ${body}`);\n}","handlingStrategy":"retry","validationCode":"const clean = packages.filter(p => typeof p === 'string' && /^[a-z0-9@\\-._/]+$/i.test(p));\nif (clean.length === 0) throw new Error('No valid packages to install');","typeGuard":"function isOkResponse(r: Response): r is Response & { ok: true } { return r.ok; }","tryCatchPattern":"try {\n  const res = await fetch('/api/install', installInit);\n  if (!res.ok) throw new InstallHttpError(res.status, res.statusText);\n  ...\n} catch (e) {\n  if (e instanceof InstallHttpError && e.status >= 500) { await sleep(1000); return installPackages(packages, true); }\n  addChatMessage(`Install failed: ${e.message}`, 'system');\n}","preventionTips":["Check server route logs for the real cause behind non-OK statuses","Ensure sandbox credentials exist in the deployed environment","Recreate the sandbox server-side before retrying installs","Include response body text in thrown messages for debuggability"],"tags":["http","api","network","npm"],"backgroundTag":"http-request-failed","analyzedSha":"69bd93bae7a9c97ef989eb70aabe6797fb3dac89","analyzedAt":"2026-08-28T22:20:32.339Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}