{"record":{"id":"56f955be56d6b5d5","repo":"mozilla/pdf.js","slug":"no-default-preferences-found-in-dir","errorCode":null,"errorMessage":"No default preferences found in \"${dir}\".","messagePattern":"No default preferences found in \"(.+?)\"\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gulpfile.mjs","lineNumber":1224,"sourceCode":"}\n\nfunction getDefaultPreferences(dir) {\n  console.log(`\\n### Parsing default preferences (${dir})`);\n\n  const require = process\n    .getBuiltinModule(\"module\")\n    .createRequire(import.meta.url);\n\n  const { AppOptions, OptionKind } = require(\n    \"./\" + DEFAULT_PREFERENCES_DIR + dir + \"app_options.mjs\"\n  );\n\n  const prefs = AppOptions.getAll(\n    OptionKind.PREFERENCE,\n    /* defaultOnly = */ true\n  );\n  if (Object.keys(prefs).length === 0) {\n    throw new Error(`No default preferences found in \"${dir}\".`);\n  }\n  return prefs;\n}\n\nfunction getDefaultFtl() {\n  const content = fs.readFileSync(\"l10n/en-US/viewer.ftl\").toString(),\n    stringBuf = [];\n\n  // Strip out comments and line-breaks.\n  const regExp = /^\\s*#/;\n  for (const line of content.split(\"\\n\")) {\n    if (!line || regExp.test(line)) {\n      continue;\n    }\n    stringBuf.push(line);\n  }\n  return stringBuf.join(\"\\n\");\n}","sourceCodeStart":1206,"sourceCodeEnd":1242,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/gulpfile.mjs#L1206-L1242","documentation":"getDefaultPreferences(dir) first runs webpack over `web/app_options.js` to emit `app_options.mjs`, requires it, and calls `AppOptions.getAll(OptionKind.PREFERENCE, defaultOnly=true)`. If that returns an empty object, no preference-kind options were found, which means the webpack bundling of app_options.js silently produced an empty/broken module or app_options.js itself has no PREFERENCE entries. The guard prevents shipping a build with an empty preferences blob, which would break the viewer's defaults.","triggerScenarios":"The webpack2Stream step failed without throwing but emitted an empty module; app_options.js was edited to remove all PREFERENCE-kind options; the `dir` argument points at a stale/incorrect output path so the require resolves a wrong/empty module; an import in app_options.js failed to resolve under the bundler and AppOptions ended up undefined (would usually throw earlier, but a default-export shape mismatch can yield an empty getAll).","commonSituations":"Editing web/app_options.js while restructuring options; a broken webpack config after a dependency upgrade; running a build task that depends on default preferences before the bundle step has produced them.","solutions":["Inspect `build/<build>/default_preferences/<dir>/app_options.mjs` — confirm it actually contains the option definitions and isn't empty.","Re-run the bundling step that produces app_options.mjs (defaultPreferencesConfig) and check for webpack errors in its output.","Verify web/app_options.js still defines options with `OptionKind.PREFERENCE`; if you removed them all, re-add at least one or reconsider the change.","Ensure the `dir` argument matches a real output directory produced by the webpack pipe."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { readFileSync, existsSync } from 'fs';\nfunction preflightPreferences(dir) {\n  const p = `${DEFAULT_PREFERENCES_DIR}${dir}app_options.mjs`;\n  if (!existsSync(p)) throw new Error(`app_options.mjs missing at ${p}; run the bundle step`);\n  const src = readFileSync(p, 'utf8');\n  if (!/PREFERENCE/.test(src)) throw new Error(`${p} has no PREFERENCE-kind options`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  prefs = getDefaultPreferences(dir);\n} catch (e) {\n  if (/No default preferences found/.test(e.message)) {\n    // rerun the webpack bundle that emits app_options.mjs, then retry once\n    await bundleDefaultPreferences(dir);\n    prefs = getDefaultPreferences(dir);\n  } else throw e;\n}","preventionTips":["Run the app_options webpack step before any task that consumes default preferences.","Keep at least one OptionKind.PREFERENCE entry in web/app_options.js.","Watch webpack output for silent failures (empty module emitted)."],"tags":["build","configuration","preferences","webpack","app-options"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}