question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'hex' of undefined (only with v2.3.0)

See original GitHub issue

Hi,

I use chalk to add colors to console logs in a personal project (create-cozy-app) and thanks a lot for your great job on this module 👍

But something seems broken since the version 2.3.0. I use almost only the chalk.hex() method and I got this issue:

myapptest/node_modules/cozy-scripts/node_modules/chalk/index.js:82
				const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
				                                                  ^

TypeError: Cannot read property 'hex' of undefined
    at Function.<anonymous> (myapptest/node_modules/cozy-scripts/node_modules/chalk/index.js:82:55)
    at Object.<anonymous> (myapptest/node_modules/cozy-scripts/utils/_colorize.js:7:15)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)

All work well with the version 2.2.2 but also if I only use default colors (chalk.blue(), chalk.bgWhite()). And it seems to concern only my webpack usage like here or here. I suppose that came from this commit so: https://github.com/chalk/chalk/commit/7be154c074026f77b99e7d854b3a4cdd5e4ae502

Hope that will help.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
danfuzzcommented, Feb 6, 2018

Thanks to @partheseas’s work mentioned in #224, I was able to distill out an even better demonstration. It’s not constructor-vs-not (that was a red herring) but rather what level is enabled:

const chalk = require("chalk")

const c1 = new chalk.constructor({ level: 1 });
const c2 = new chalk.constructor({ level: 2 });
const c3 = new chalk.constructor({ level: 3 });
const c4 = new chalk.constructor({ level: 4 });
console.log(c1.hex('123')('foo'));
console.log(c2.hex('123')('foo'));
console.log(c3.hex('123')('foo'));
console.log(c4.hex('123')('foo'));

This example works, except for the last line, which fails per the original description of this bug.

1reaction
danfuzzcommented, Feb 21, 2018

Oh, my apologies. I thought it went to 4. (By way of suggestion, maybe the constructor should throw if given a bogus level.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript Error: Uncaught TypeError: Cannot read property ...
First, you need to run your script after the entire DOM has loaded. If you run your script before the DOM has fully...
Read more >
How to Read React Errors (fix 'Cannot read property of ...
Cannot read property means the code was trying to read a property. This is a good clue! There are only a few ways...
Read more >
cannot read properties of undefined (reading 'icon') - You.com
Here the error is coming from line 2: value: {Icon, name, level} . The value coming via props seems to be undefined. Check...
Read more >
Crypto | Node.js v19.3.0 Documentation
The node:crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify ...
Read more >
ThemeData class - material library - Flutter - Dart API docs
These properties are guaranteed to have non-null values. The static Theme.of ... 'This feature was deprecated after v2.3.0-0.1.pre. ... read-onlyoverride.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found