Debug: Doesn't work with dotenv anymore.

Created on 15 May 2019  路  18Comments  路  Source: visionmedia/debug

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.

Most helpful comment

馃憢 maintainer of dotenv here. from what I was able to reproduce in https://github.com/motdotla/dotenv/pull/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 馃樃)

All 18 comments

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

@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\"",

Okay but I mean what specifically isn't working?

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

Right, so what is DEBUG set to?

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.

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

@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.

@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

@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).

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.

@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')

@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.

馃憢 maintainer of dotenv here. from what I was able to reproduce in https://github.com/motdotla/dotenv/pull/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 馃樃)

Thanks for checking in @maxbeatty :)

@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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Qix- picture Qix-  路  4Comments

krismeister picture krismeister  路  6Comments

jfoclpf picture jfoclpf  路  6Comments

BertCatsburg picture BertCatsburg  路  5Comments

Qix- picture Qix-  路  7Comments