{"record":{"id":"7eb3cf36487607f1","repo":"motdotla/dotenv","slug":"object-required","errorCode":"OBJECT_REQUIRED","errorMessage":"OBJECT_REQUIRED: Please check the processEnv argument being passed to populate","messagePattern":"OBJECT_REQUIRED: Please check the processEnv argument being passed to populate","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/main.d.ts","lineNumber":121,"sourceCode":"\n  /**\n   * Default: `process.env`\n   *\n   * Specify an object to write your secrets to. Defaults to process.env environment variables.\n   *\n   * example: `const processEnv = {}; require('dotenv').config({ processEnv: processEnv })`\n   */\n  processEnv?: DotenvPopulateInput;\n\n}\n\nexport interface DotenvConfigOutput {\n  error?: DotenvError;\n  parsed?: DotenvParseOutput;\n}\n\ntype DotenvError = Error & {\n  code: 'OBJECT_REQUIRED' | 'SECURE_REQUIRES_DOTENVX';\n}\n\nexport interface DotenvPopulateOptions {\n  /**\n   * Default: `false`\n   *\n   * Turn on logging to help debug why certain keys or values are not being set as you expect.\n   *\n   * example: `require('dotenv').populate(processEnv, parsed, { debug: true })`\n   */\n  debug?: boolean;\n\n  /**\n   * Default: `false`\n   *\n   * Override any environment variables that have already been set on your machine with values from your .env file.\n   *\n   * example: `require('dotenv').populate(processEnv, parsed, { override: true })`","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/motdotla/dotenv/blob/2fc7eac8ad77cbd5f7814355c7fa352dbcf3c358/lib/main.d.ts#L103-L139","documentation":"This error is thrown by dotenv's populate() helper when the processEnv argument is not a valid plain object. populate() copies parsed key/value pairs into a target object (usually process.env), and it explicitly validates that the target is assignable via Object.defineProperty / assignment. If you pass undefined, null, a primitive, or a non-object, dotenv aborts with code OBJECT_REQUIRED instead of silently failing.","triggerScenarios":"Calling dotenv.populate(parsed, processEnv) where processEnv is undefined/null (e.g. a variable that was never assigned), or passing a primitive such as a string, number, or boolean, or passing an object created with Object.create(null) in older versions lacking a prototype, or calling the typed overload from lib/main.d.ts:121 with mismatched arguments so the target argument is missing at runtime.","commonSituations":"Refactoring code so the second argument to populate() was accidentally dropped or renamed; importing populate() and swapping the argument order (passing the parsed object where the env target belongs); storing process.env in a variable that ends up undefined in a bundled/SSR environment (e.g. serverless or edge runtimes where process is polyfilled oddly); calling populate() before any target object exists in custom env-loading utilities.","solutions":["Pass a real object as the processEnv argument — typically process.env itself: dotenv.populate(parsed, process.env).","If you use a custom target, initialize it first: const env = {}; dotenv.populate(parsed, env).","Check argument order: the signature is populate(processEnv, parsed) — make sure the target object is first, not the parsed result.","Log/inspect the value right before the call (console.log(typeof processEnv)) to confirm it is 'object' and not null/undefined.","If running in an environment where process is not defined (edge/serverless), create a shim object instead of relying on a missing global."],"exampleFix":"// before\nconst parsed = dotenv.config().parsed\ndotenv.populate(parsed, myEnv) // myEnv is undefined -> OBJECT_REQUIRED\n\n// after\nconst parsed = dotenv.config().parsed\nconst myEnv = myEnv || {}\ndotenv.populate(myEnv, parsed) // correct order, valid object target","handlingStrategy":"validation","validationCode":"function canPopulate(target) {\n  return typeof target === 'object' && target !== null\n}\n// before calling:\nif (!canPopulate(myEnv)) throw new TypeError('populate requires an object as processEnv')","typeGuard":"function isPopulateTarget(v: unknown): v is Record<string, string> {\n  return typeof v === 'object' && v !== null\n}","tryCatchPattern":"try {\n  dotenv.populate(processEnv, parsed)\n} catch (err: any) {\n  if (err && err.code === 'OBJECT_REQUIRED') {\n    console.error('populate() target must be an object; got', typeof processEnv)\n    processEnv = processEnv && typeof processEnv === 'object' ? processEnv : {}\n    dotenv.populate(processEnv, parsed)\n  } else {\n    throw err\n  }\n}","preventionTips":["Always pass process.env (or a freshly created {}) as the populate target — never a variable that may be undefined.","Enable TypeScript strict mode so the lib/main.d.ts typing (DotenvPopulateOptions / processEnv: object) catches bad arguments at compile time.","Keep argument order straight: target object first, parsed result second.","In serverless/edge runtimes, verify the process global exists before calling any dotenv API.","Wrap populate() calls in a small utility that validates inputs once instead of calling it ad hoc."],"tags":["dotenv","typescript","arguments","object-required"],"backgroundTag":"invalid-function-arguments","analyzedSha":"2fc7eac8ad77cbd5f7814355c7fa352dbcf3c358","analyzedAt":"2026-09-02T02:18:13.149Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}