dotenv icon indicating copy to clipboard operation
dotenv copied to clipboard

Bug: populate() is not a function

Open marigarey opened this issue 1 year ago • 3 comments

When I use the populate function, my code returns the error: "TypeError: dotenv.populate is not a function".

My code:

const parsed = {TEST: 'test'}
dotenv.populate(process.env, parsed)

Not sure what is wrong, hopefully its on my end!

marigarey avatar Jun 16 '24 23:06 marigarey

it probably just hasnt been added to the types file. dotenv has never been a typescript project. you can either define your own type in your project for it or if you have time a PR contribution to add it to the project's type file would be very welcome :)

motdotla avatar Jun 17 '24 14:06 motdotla

i've been using javascript, but I can try to look through the code and see how to fix it!

(also thank you for your dotenv work! your work makes my life so much easier!!)

marigarey avatar Jun 19 '24 00:06 marigarey

Hi, I am a programmer trying to get into open-source contribution and wanted to chime in here. It seems like populate is already defined in the lib/main.d.ts types file:

/**
 * Loads `source` json contents into `target` like process.env.
 *
 * See https://dotenvx.com/docs
 *
 * @param processEnv - the target JSON object. in most cases use process.env but you can also pass your own JSON object
 * @param parsed - the source JSON object
 * @param options - additional options. example: `{ debug: true, override: false }`
 * @returns {void}
 *
 */
export function populate(processEnv: DotenvPopulateInput, parsed: DotenvPopulateInput, options?: DotenvConfigOptions): void;

Not sure if I'm looking in the right place, maybe it's a config issue on the user's end?

mrinal-c avatar Jul 04 '24 17:07 mrinal-c