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.

undefined is not an object when used in a React Native project.

See original GitHub issue

Hello,

I’m messing around with React Native and I wanted to try using chalk to help make some of the logs more clear. I’m running into an issue though at the import/require step.

If I try import chalk from 'chalk'; or const chalk = require('chalk'); I receive the following error:

screen shot 2016-12-28 at 4 06 12 pm

Here are the output of the React Packager:

[12/28/2016, 3:59:04 PM] <START> Requesting bundle bundle_url: /index.ios.bundle?platform=ios&dev=true&minify=false
[12/28/2016, 3:59:04 PM] <END>   Requesting bundle bundle_url: /index.ios.bundle?platform=ios&dev=true&minify=false (25ms)
[12/28/2016, 3:59:04 PM] <START> Symbolicating
[12/28/2016, 3:59:04 PM] <END>   Symbolicating (319ms)
[12/28/2016, 3:59:04 PM] <START> Symbolicating
[12/28/2016, 3:59:05 PM] <END>   Symbolicating (306ms)

If I’m following the stack trace correctly its complaining about lines 2-4 in supports-color/index.js:

var argv = process.argv;

var terminator = argv.indexOf('--');

Further info: OS: OSX v10.11.6 Node: v5.9.1 NPM: v3.10.8 React Native: v0.39.2 Chalk: v^1.1.3

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Qix-commented, Dec 29, 2016

Well process.argv is going to be your first of several problems. We also check the environment (which may not exist either), and specifically the $TERM env variable. You’re going to have to emulate those if you want to do any of that.

Chalk is really for terminal emulators (console, terminals, etc.). If you’re not running on one of those, Chalk isn’t really going to help you much.

0reactions
AndrewKvalheimcommented, Oct 30, 2017

Ran into this when trying to use Chalk with FORCE_COLOR while logging in React Native. sindresorhus/has-flag#3 suggests that React Native should provide a process.argv.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting undefined is not an object in React native when ...
First, the prop you pass to RenderPhotos is this.props.photos , which is undefined in AwesomeProject . Looking in the render() function of ...
Read more >
TypeError: undefined is not an object – React - DPS Computing
Simply, you're treating a variable like it is an object when it is not. 'undefined' means that your variable hasn't yet been defined...
Read more >
Render Error undefined is not an Object (evaluating _react ...
Render Error undefined is not an Object (evaluating _react.react .createElement) Fixed- React Native.
Read more >
undefined is not an object (evaluating 'device.id') in ... - YouTube
How to Add Apollo Client to React Native | React Native Tutorial · ERROR TypeError: undefined is not an object (evaluating '_reactNative. ·...
Read more >
ERROR TypeError: undefined is not an object (evaluating ...
Ever encountered this error → ERROR TypeError: undefined is not an object (evaluating '_this.props.navigation.navigate') whilst working hard on your project?
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