Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling dotenv.config() results in a TypeError #605

Closed
bankslenus opened this issue Jan 25, 2022 · 2 comments
Closed

Calling dotenv.config() results in a TypeError #605

bankslenus opened this issue Jan 25, 2022 · 2 comments

Comments

@bankslenus
Copy link

Since upgrading from dotenv 14.2.0 to 14.3.0 I get the following error when calling dotenv.config()

CODE (foo.js):

...
import * as dotenv from "dotenv";
dotenv.config(); // line 20
...

ERROR:

$ yarn build
$ tslint -c tslint.json -p tsconfig.json --fix
$ tsc
$ node --es-module-specifier-resolution=node .
file:///..../foo.js:20
dotenv.config();
       ^

TypeError: dotenv.config is not a function
    at file:///..../foo.js:20:8
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Downgrading to 14.2.0 solves the error.

@JeromeFitz
Copy link
Contributor

Downgrading to 14.2.0 is an option. Thanks for identifying and suggesting @bankslenus

14.3.0 exports as default currently: main.js.

[Module: null prototype] {
  default: { config: [Function: config], parse: [Function: parse] }
}

For now you can do:

import dotenv from "dotenv";

Aside:

In one of my cases I was dynamically importing (only loading on local development not CI) and needed to change to this:

...
  const dotenv = await import('dotenv')
  dotenv.default.config({ path: './.env' })
...

Though this would work too:

...
  const {
    default: { config },
  } = await import('dotenv')
  config({ path: './.env' })
...

The code change looks to come in from this commit:

Before:

module.exports.config = config
module.exports.parse = parse

After:

const DotenvModule = {
   config,
   parse
 }

 module.exports = DotenvModule

Will see if we can double-up the module.exports as a patch for the interim to see if going to 14.3.1 is an option for backward compatibility, or if a different direction is preferred.

JeromeFitz added a commit to JeromeFitz/dotenv that referenced this issue Jan 25, 2022
motdotla added a commit that referenced this issue Jan 25, 2022
patch for 14.3.0, add back explicit module.exports #605
@motdotla
Copy link
Owner

This is patched in 14.3.1. So sorry about this one. Thanks to @JeromeFitz for the quick patch.

https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md#1431-2022-01-25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants