Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tetreault opened this issue Dec 28, 2016 · 6 comments
Closed

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

tetreault opened this issue Dec 28, 2016 · 6 comments

Comments

@tetreault
Copy link

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

@Qix-
Copy link
Member

Qix- commented Dec 29, 2016

I'm not seeing how that stack trace is pointing to supports-color. I've not played with react native but does process.argv not exist in that environment?

@tetreault
Copy link
Author

@Qix- when I click on the top index.js line 4 it brings me to the index.js for supports-color. To be honest I'm not sure if process.argv exists in that environment and guess I'll have to figure that out. I posted this here because I hadn't seen it anywhere, and it is definitely happening at the require/import step when I try to use chalk. I'll try more digging and maybe xposting to SO to see what else I can find out.

@Qix-
Copy link
Member

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.

@tetreault
Copy link
Author

Okay fair enough, thank you for your help!

@Qix-
Copy link
Member

Qix- commented Dec 29, 2016

No problem! Sorry I couldn't be of more help.

@Qix- Qix- closed this as completed Dec 29, 2016
@AndrewKvalheim
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants