{"record":{"id":"979151cf36a3df3e","repo":"CherryHQ/cherry-studio","slug":"unsupported-linux-packaging-architecture-contex-979151","errorCode":null,"errorMessage":"Unsupported Linux packaging architecture: ${context.arch}","messagePattern":"Unsupported Linux packaging architecture: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/before-pack.js","lineNumber":118,"sourceCode":"    throw new Error(\n      `Missing prebuilt packages for ${platform}-${arch}: ${missingPackages.join(', ')}\\n` +\n        `Run \\`rm -rf node_modules && pnpm install\\` — pnpm only reads supportedArchitectures ` +\n        `on a fresh install, so plain \\`pnpm install\\` (even --force) will not fix it.`\n    )\n  }\n}\nexports.assertPrebuiltPackages = assertPrebuiltPackages\n\nexports.default = async function (context) {\n  const arch = context.arch === Arch.arm64 ? 'arm64' : 'x64'\n  const platformName = context.packager.platform.name\n  const platform = platformToArch[platformName]\n\n  assertPrebuiltPackages(platform, arch)\n\n  if (platform === 'linux') {\n    const linuxArch = context.arch === Arch.arm64 ? 'arm64' : context.arch === Arch.x64 ? 'x64' : null\n    if (!linuxArch) throw new Error(`Unsupported Linux packaging architecture: ${context.arch}`)\n\n    const projectRoot = path.join(__dirname, '..')\n    const artifact = ensureLinuxNativeArtifact({ projectRoot, arch: linuxArch })\n    process.stdout.write(\n      `${artifact.cached ? 'Verified cached' : 'Downloaded'} GLIBC-compatible better-sqlite3 for ` +\n        `linux-${linuxArch} (${artifact.inspection.sha256})\\n`\n    )\n  }\n\n  console.log(`Downloading bundled binaries for ${platform}-${arch}...`)\n  execSync(`node \"${path.join(__dirname, 'download-binaries.js')}\" ${platform} ${arch}`, { stdio: 'inherit' })\n  // Fail the build rather than ship a half-empty resources/binaries/<platform>.\n  require('./download-binaries').verifyBundledBinaries(platform, arch)\n\n  const excludePackages = async (packagesToExclude) => {\n    // 从项目根目录的 electron-builder.yml 读取 files 配置，避免多次覆盖配置导致出错\n    const electronBuilderConfigPath = path.join(__dirname, '..', 'electron-builder.yml')\n    const electronBuilderConfig = parse(fs.readFileSync(electronBuilderConfigPath, 'utf-8'))","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/scripts/before-pack.js#L100-L136","documentation":"Thrown by scripts/before-pack.js (the electron-builder before-pack hook) when packaging for Linux on an architecture that is neither arm64 nor x64. The hook must select a GLIBC-compatible better-sqlite3 native artifact keyed by arch; only arm64 and x64 have verified artifacts. This fires earlier than the after-pack equivalent, before the native artifact is downloaded.","triggerScenarios":"Running an electron-builder Linux target with --arch set to ia32, armv7l, or another unsupported value (e.g. npx electron-builder --linux --ia32). The context.arch is compared against Arch.arm64 and Arch.x64; anything else yields null.","commonSituations":"CI matrix with an unsupported Linux arch; a leftover ia32/armv7l target in the electron-builder config; upgrading electron-builder where Arch enum numeric values shifted; copy-pasting a build target without confirming native artifact availability.","solutions":["Build Linux only for x64 and arm64 — the only arches with a verified GLIBC better-sqlite3 artifact.","Remove the unsupported arch from electron-builder config / CI matrix.","To support a new arch, first add and verify a better-sqlite3 artifact in scripts/linux-native/, then extend the arch ternary in both before-pack.js and after-pack.js.","Verify the --arch value resolves to Arch.x64 or Arch.arm64 in the installed electron-builder version."],"exampleFix":"// electron-builder.yml (before)\nlinux:\n  target:\n    - ia32\n    - x64\n\n// after\nlinux:\n  target:\n    - x64\n    - arm64","handlingStrategy":"validation","validationCode":"const SUPPORTED_LINUX_ARCH = new Set(['x64', 'arm64'])\nif (platform === 'linux' && !SUPPORTED_LINUX_ARCH.has(arch)) {\n  throw new Error(`Refusing to pack linux on unsupported arch '${arch}'`)\n}","typeGuard":"const isSupportedLinuxArch = (a: string): boolean => a === 'x64' || a === 'arm64'","tryCatchPattern":null,"preventionTips":["Restrict Linux packaging to x64 and arm64.","Provide a better-sqlite3 artifact before enabling any new arch.","Validate arch in CI before the packaging step."],"tags":["build","electron-builder","linux","packaging","native-modules"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}