Debug: How to use in a create-react-app and webpack 4?

Created on 6 Jan 2019  路  4Comments  路  Source: visionmedia/debug

I have installed debug:

$ npm install --debug

The installed version is 4.1.1

I have the following source code:

import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import debug from 'debug';
const logger = debug('Routes');

const list = [];
const makeRoutes = (routes) => {
  routes.forEach((route) => {
    if (list.filter((l) => l.key === route.name).length === 0) {
      route.from ?
        logger(`creating redirect ${route.name} with to ${route.to}`) || list.push(<Redirect key={route.name} {...route} />)
        : logger(`creating route ${route.name} with path ${route.path}`) || list.push(<Route key={route.name} {...route} />);
      routes.childRoutes && logger(routes.childRoutes);
      routes.childRoutes && makeRoutes(routes.childRoutes);
    }
  });
  return list;
};

export default ({ routes }) => (
  <Switch>
    {makeRoutes(routes)}
  </Switch>
);

I am trying to enable debugging by doing:

echo "DEBUG=:*" | tee -a .env

I have also tried to install craco and add the following webpack configuration:

```js
webpack: {
plugins: [
new webpack.DefinePlugin({
'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
}),
],
},
````

The documentation say that it also work for browser, how can I enable debug output in my console using create-react-app and webpack 4

Thanks in advance and keep up the good work!

question

Most helpful comment

No, it's a runtime variable - what you have there (DEBUG=* npm start) should suffice.

All 4 comments

It's not :*, it's just *.

@Qix- thanks for your quick reply. Does DEBUG=* npm start would be sufficient to enable logging or does this needs to be configured in webpack configuration so it's included in my application context?

No, it's a runtime variable - what you have there (DEBUG=* npm start) should suffice.

Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adamcohenrose picture adamcohenrose  路  3Comments

Qix- picture Qix-  路  7Comments

roccomuso picture roccomuso  路  8Comments

anishkny picture anishkny  路  6Comments

BertCatsburg picture BertCatsburg  路  5Comments