motdotla / dotenv

Loads environment variables from .env for nodejs projects.
https://www.dotenvx.com
BSD 2-Clause "Simplified" License
19.01k stars 853 forks source link

Bug: populate() is not a function #830

Open marigarey opened 2 months ago

marigarey commented 2 months ago

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!

motdotla commented 2 months ago

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 :)

marigarey commented 2 months ago

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!!)

mrinal-c commented 2 months ago

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?