Search code examples
javascriptecmascript-6chalk

chalk.bgHex is not a function


I'm using chalk version ^1.1.3

No idea why it's saying that the method is not recognized:

const chalk = require('chalk'),
  _ = require('lodash'),
  info = chalk.yellow,
  green = chalk.green,
  script = chalk.bgHex('#ebd2f8')

Error: chalk.bgHex is not a function

I also don't know how I'd append a text color on top of that background.


Solution

  • The commit that introduced hex/bgHex was committed just 2 hours ago. There hasn't been a new publish to the NPM repository with that commit.

    If you want to use it, you can use the GitHub-hosted version of the module:

    $ npm i chalk/chalk
    

    However, do so with extreme caution. There's probably a reason why the developers haven't published a new version yet (i.e. it's not finished).