{"record":{"id":"803df10ccf0a8248","repo":"langgenius/dify","slug":"cannot-resolve-appdata-on-windows","errorCode":null,"errorMessage":"cannot resolve %APPDATA% on Windows","messagePattern":"cannot resolve %APPDATA% on Windows","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/sys/index.ts","lineNumber":101,"sourceCode":"    },\n    cacheDir: () => {\n      const xdg = getEnv(ENV_XDG_CACHE_HOME)\n      return xdg !== undefined && xdg !== '' ? join(xdg, SUBDIR) : join(homedir(), '.cache', SUBDIR)\n    },\n    atomicReplace: posixAtomicReplace,\n  }),\n  darwin: () => ({\n    id: () => 'darwin',\n    configDir: () => join(homedir(), '.config', SUBDIR),\n    cacheDir: () => join(homedir(), 'Library', 'Caches', SUBDIR),\n    atomicReplace: posixAtomicReplace,\n  }),\n  win32: () => ({\n    id: () => 'win32',\n    configDir: () => {\n      const appData = appDataDir()\n      if (appData === undefined || appData === '')\n        throw new Error('cannot resolve %APPDATA% on Windows')\n      return join(appData, SUBDIR)\n    },\n    cacheDir: () => {\n      const appData = appDataDir()\n      if (appData === undefined || appData === '')\n        throw new Error('cannot resolve %LOCALAPPDATA% on Windows')\n      return join(appData, SUBDIR)\n    },\n    atomicReplace: win32AtomicReplace,\n  }),\n}\n\nconst defaultPlatformFactory: PlatformFactory = () => ({\n  id: () => platform(),\n  configDir: () => join(homedir(), '.config', SUBDIR),\n  cacheDir: () => join(homedir(), '.cache', SUBDIR),\n  atomicReplace: posixAtomicReplace,\n})","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/cli/src/sys/index.ts#L83-L119","documentation":"A bare Error thrown by the win32 platform's configDir (sys/index.ts:101) when appDataDir() returns undefined or ''. appDataDir reads `getEnv('APPDATA') ?? getEnv('LOCALAPPDATA')` — so the throw fires only when BOTH APPDATA and LOCALAPPDATA are unset/empty on Windows. On a healthy Windows install these are always set by the OS/user profile; their absence indicates a broken environment. Linux/darwin use different factories and never hit this. The error blocks any operation that needs the config dir (hosts.yml path, etc.).","triggerScenarios":"Running difyctl on Windows under a context where the user profile env vars weren't propagated: a service account, Task Scheduler with no profile, sshd with a minimal env, a stripped Docker/container image, or a process launched with a hand-built environment that omitted APPDATA/LOCALAPPDATA.","commonSituations":"Windows Server scheduled task running as SYSTEM (which has no APPDATA in the normal per-user sense); containers based on Windows Server Core with a minimal profile; CI runners (GitHub Actions windows-latest usually sets them, but custom self-hosted may not); SSH into a Windows host with a non-interactive shell that skips profile loading.","solutions":["Set the env vars explicitly before running difyctl (PowerShell): `$env:APPDATA=\"$env:USERPROFILE\\AppData\\Roaming\"; difyctl ...`.","For service accounts / Task Scheduler: configure the task to load the user profile, or set APPDATA/LOCALAPPDATA in the task's environment block to a writable dir.","In containers, set APPDATA at image build time: `ENV APPDATA=C:\\Users\\ContainerAdministrator\\AppData\\Roaming`.","For SSH sessions, ensure the user's logon profile loads (use a fully interactive shell or set the vars in the sshd environment).","If the profile is genuinely broken, recreate it or pick an explicit config dir via any difyctl-supported XDG override (note: the win32 factory here does NOT honor XDG_CONFIG_HOME — only the linux factory does — so you must set APPDATA)."],"exampleFix":"# before — difyctl invoked with no APPDATA on Windows\n> difyctl auth login\nError: cannot resolve %APPDATA% on Windows\n\n# after — set APPDATA/LOCALAPPDATA explicitly (PowerShell)\n$env:APPDATA = \"$env:USERPROFILE\\AppData\\Roaming\"\n$env:LOCALAPPDATA = \"$env:USERPROFILE\\AppData\\Local\"\ndifyctl auth login","handlingStrategy":"validation","validationCode":"// on Windows, assert APPDATA/LOCALAPPDATA are set before invoking difyctl\nfunction assertWindowsProfile(): void {\n  if (process.platform !== 'win32') return\n  const appData = process.env.APPDATA ?? process.env.LOCALAPPDATA\n  if (appData === undefined || appData === '') {\n    throw new Error('set APPDATA/LOCALAPPDATA before running difyctl on Windows')\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run difyctl in a context where the Windows user profile is loaded (interactive shell, profile-loading task).","For service accounts, explicitly set APPDATA and LOCALAPPDATA in the environment.","In Windows containers, set APPDATA in the image."],"tags":["windows","environment","config-dir","platform","appdata"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}