{"record":{"id":"a985b3b46f73b8bc","repo":"parcel-bundler/parcel","slug":"certificate-and-or-key-not-found","errorCode":null,"errorMessage":"Certificate and/or key not found","messagePattern":"Certificate and/or key not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/utils/src/getCertificate.js","lineNumber":15,"sourceCode":"// @flow\nimport type {HTTPSOptions} from '@parcel/types';\nimport type {FileSystem} from '@parcel/fs';\n\nexport default async function getCertificate(\n  fs: FileSystem,\n  options: HTTPSOptions,\n): Promise<{|cert: Buffer, key: Buffer|}> {\n  try {\n    let cert = await fs.readFile(options.cert);\n    let key = await fs.readFile(options.key);\n\n    return {key, cert};\n  } catch (err) {\n    throw new Error('Certificate and/or key not found');\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/utils/src/getCertificate.js#L1-L18","documentation":"Thrown by getCertificate when reading either options.cert or options.key via fs.readFile fails. Used by Parcel's dev server to obtain HTTPS material; any read error (missing file, permission denied, ENOENT) is collapsed into a single generic message, hiding which file failed.","triggerScenarios":"Starting `parcel serve`/`parcel dev` with --cert and --key flags (or HTTPSOptions) pointing to paths that do not exist, are unreadable, or are directories.","commonSituations":"Cert/key path typos; relative paths resolved against the wrong cwd; certs gitignored and missing after clone; permission/ownership issues on the key file; passing only one of cert/key.","solutions":["Verify both cert and key files exist and are readable: `ls -l <cert> <key>`.","Use absolute paths for --cert and --key to avoid cwd resolution issues.","Regenerate a self-signed cert if the files are missing (`mkcert` or `openssl req -x509 ...`).","Check file permissions/ownership so the Parcel process can read them."],"exampleFix":"// before\ngetCertificate(fs, { cert: 'cert.pem', key: 'key.pem' }); // ENOENT\n\n// after\ngetCertificate(fs, {\n  cert: path.resolve('certs/cert.pem'),\n  key:  path.resolve('certs/key.pem'),\n});","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nfunction assertCertFiles(opts) {\n  for (const k of ['cert','key']) {\n    if (!opts[k] || !fs.existsSync(opts[k])) {\n      throw new Error(`HTTPS ${k} file missing: ${opts[k] ?? '(unset)'}`);\n    }\n  }\n}\nassertCertFiles(httpsOptions);","typeGuard":"interface HTTPSOptions { cert: string; key: string; }\nfunction hasValidCertPaths(o: Partial<HTTPSOptions>): o is HTTPSOptions {\n  return typeof o.cert === 'string' && typeof o.key === 'string';\n}","tryCatchPattern":"try { await getCertificate(fs, opts); }\ncatch (e) {\n  if (/Certificate and\\/or key not found/.test(e.message)) {\n    // regenerate or fix paths, then retry\n  } else throw e;\n}","preventionTips":["Use absolute paths for --cert/--key.","Commit a script to regenerate self-signed certs (mkcert) for new checkouts.","Verify file readability (permissions) before starting the dev server."],"tags":["https","dev-server","certificate","filesystem"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}