Marak / colors.js

get colors in your node.js console
https://github.com/Marak/colors.js
Other
5.17k stars 446 forks source link

Webpack error: 141:29-43 Critical dependency: the request of a dependency is an expression #200

Closed PDS42 closed 6 years ago

PDS42 commented 7 years ago

Hello, I've been struggling with this issue for a few days now. What's bothering me here is the following error: WARNING in ./node_modules/colors/lib/colors.js 141:29-43 Critical dependency: the request of a dependency is an expression. I can make the other errors go away, but not this one. From what I've read so far, a dynamic require might cause this issue. I'm really unsure how to fix this. Any help appreciated!

Screenshot of the error

jpap commented 6 years ago

You're exactly right; the warning is a result of the setTheme method below, and is caused by the require(theme) in the try-block.

colors.setTheme = function (theme) {
  if (typeof theme === 'string') {
    try {
      colors.themes[theme] = require(theme);
      applyTheme(colors.themes[theme]);
      return colors.themes[theme];
    } catch (err) {
      console.log(err);
      return err;
    }
  } else {
    applyTheme(theme);
  }
};

I'd love if there was a way to silence the webpack warning as it is otherwise tarnishing a clean build -- this package is a dependency of winston which I am using in a project.

This code path appears to be a way in which to include a theme from a JS module; but the official docs in the README leave it undocumented. Perhaps it's worth removing it altogether?

It looks like this has been discussed at length in #137.

jpap commented 6 years ago

I'd say this is a dupe of #137 and can be closed...

DABH commented 6 years ago

Going to close this in favor of #137 , and hopefully resolve the issue over there... thanks for the discussion on this!