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

Doesn't work with dotenv anymore. #705

Closed
botond-veress opened this issue May 15, 2019 · 18 comments
Closed

Doesn't work with dotenv anymore. #705

botond-veress opened this issue May 15, 2019 · 18 comments

Comments

@botond-veress
Copy link

botond-veress commented May 15, 2019

The following code snippet works with the version 3.2.6 but it doesn't work with 4.1.1.

import dotenv from 'dotenv';

dotenv.config();

const debug = require('debug');

const log = debug('app');
log('Something');

I've checked the 4.x change logs but I couldn't find anything related to this.

@Qix-
Copy link
Member

Qix- commented May 15, 2019

There shouldn't be. What's your environment configuration related to debug?

@botond-veress
Copy link
Author

@Qix- I am using babel with typescript.

"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/node": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
"@babel/register": "^7.4.4",
"nodemon": "^1.19.0",
"typescript": "^3.4.5"

I am running it with babel-node:

"watch": "nodemon src/index.ts --exec \"babel-node --extensions '.ts','.js' src/index.ts\"",

@Qix-
Copy link
Member

Qix- commented May 15, 2019

Okay but I mean what specifically isn't working?

@botond-veress
Copy link
Author

I meant by "doesn't work" that it doesn't print the message.

@Qix-
Copy link
Member

Qix- commented May 15, 2019

Right, so what is DEBUG set to?

@botond-veress
Copy link
Author

botond-veress commented May 15, 2019

It is set to app.

When I run it with DEBUG=app yarn start it logs to the console, but if I set it in the .env file it doesn't log anymore.
The process.env.DEBUG is set to app in both cases.

Note that I am using this library for a while now, but it stopped working since today when I updated it to the latest version.

@Qix-
Copy link
Member

Qix- commented May 15, 2019

Then you need to open a ticket with them; there's nothing I can do about that.

@Qix- Qix- closed this as completed May 15, 2019
@Qix- Qix- mentioned this issue May 15, 2019
11 tasks
@botond-veress
Copy link
Author

@Qix- I think you closed the issue prematurely. It is a debug issue, not a dotenv issue. As I mentioned earlier the environment variables are passed correctly to my application. debug stopped working after I updated the debug library.

@Qix-
Copy link
Member

Qix- commented May 18, 2019

@botond-veress then that means debug has stopped accepting the DEBUG variable, which isn't the case. Please verify that DEBUG is in process.env before requiring debug

@botond-veress
Copy link
Author

@Qix- It is. That's why I opened the issue.
Once I update it to 4.1.1 it stops working. If I install the old (3.2.6) version it works just fine - without touching a single line of code (just like I mentioned in my very first comment).

@Qix-
Copy link
Member

Qix- commented May 18, 2019

I'm not sure how out of many millions of downloads per week you're the only one facing the issue that DEBUG is not working. I'm not trying to sound rude, but there would be an army of people posting about this if it were broken.

@eddyw
Copy link

eddyw commented May 24, 2019

@botond-veress it works for me.
I suggest you try:

import dotenv from 'dotenv'

const env = dotenv.config()

console.dir(env.parsed) // <<<<< should include `DEBUG: '*'` from env file, for example
console.dir(env.error) // <<<<< is it `undefined`?

const debug = require('debug')
const log = debug('app')

log('Something')

@xamgore
Copy link

xamgore commented May 26, 2019

@Qix- I am the third of that army ;)

In @eddyw example env.parsed contains correct DEBUG value and env.error equals to undefined. Downgrading the debug version to 3.2.6 resolves the issue.

@maxbeatty
Copy link

👋 maintainer of dotenv here. from what I was able to reproduce in motdotla/dotenv#398 dotenv is working, debug is working, but mixing together with babel-node seems to not work as expected. if anyone would like to help complete the example in that PR (i.e. make it work), that will help identify which package, if any, needs an update ❤️ I'm also open to any other fully re-produceable examples (i.e. not code snippets in comments 😸)

@Qix-
Copy link
Member

Qix- commented May 27, 2019

Thanks for checking in @maxbeatty :)

@eddyw
Copy link

eddyw commented May 27, 2019

@xamgore I'd suggest using ts-node instead of babel-node. If you don't want the type-checking on it, use ts-node -T. At least as a temporary solution on development if production build really needs babel to polyfill stuff on the server for old NodeJS. Otherwise, TS can transform class properties and rest/spread on its own (set target: "es5" or target: "es6"), so you wouldn't actually need babel if it's the only thing you need it for. It works out-of-the-box with debug & dotenv

@toritsejuFO
Copy link

This is still an issue. Here I was thinking I was the only one having the issue till I found this thread.

@Qix-
Copy link
Member

Qix- commented Feb 3, 2020

This thread has nothing actionable. Please take it to the appropriate channels.

@debug-js debug-js locked as off-topic and limited conversation to collaborators Feb 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

6 participants