Create-react-native-app: TypeError: Cannot read property 'on' of undefined

Created on 25 Apr 2017  ·  9Comments  ·  Source: expo/create-react-native-app

Description

  1. Created a brand new project following instructions at https://facebook.github.io/react-native/blog/2017/03/13/introducing-create-react-native-app.html
  2. First time the project ran fine using npm run ios, launched iOS simulator with the example page
  3. Ctrl+C from the terminal running #2 above
  4. Run npm run ios, got the below error

Expected Behavior

See above steps

Observed Behavior

Error occurred running npm run ios the second time

ps.stdout.on('data', function (data) {
             ^
TypeError: Cannot read property 'on' of undefined
    at buildProcessTree (/Users/gbacrna_sample/run_ios_error/node_modules/tree-kill/index.js:78:14)
    at /Users/gbacrna_sample/run_ios_error/node_modules/tree-kill/index.js:99:11
    at Array.forEach (native)
    at ChildProcess.onClose (/Users/gbacrna_sample/run_ios_error/node_modules/tree-kill/index.js:94:31)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:501:12)
/Users/gbacrna_sample/run_ios_error/node_modules/tree-kill/index.js:78
    ps.stdout.on('data', function (data) {
             ^

TypeError: Cannot read property 'on' of undefined
    at buildProcessTree (/Users/gbacrna_sample/run_ios_error/node_modules/tree-kill/index.js:78:14)
    at module.exports (/Users/gbacrna_sample/run_ios_error/node_modules/tree-kill/index.js:18:9)
    at process.<anonymous> (/xdl/src/Project.js:683:5)
    at emitOne (events.js:96:13)
    at process.emit (events.js:188:7)
    at process.emit (/Users/gbacrna_sample/run_ios_error/node_modules/source-map-support/source-map-support.js:430:21)
    at process.exit (internal/process.js:147:15)
    at printErrorAndExit (/Users/gbacrna_sample/run_ios_error/node_modules/source-map-support/source-map-support.js:414:11)
    at process.emit (/Users/gbacrna_sample/run_ios_error/node_modules/source-map-support/source-map-support.js:426:16)
    at process._fatalException (bootstrap_node.js:284:26)

Environment

Please run these commands in the project folder and fill in their results:

npm ERR! peer dep missing: react@>=15.3.1, required by [email protected]
npm ERR! peer dep missing: react@>=15.4.0, required by [email protected]
npm ERR! peer dep missing: react@>=15.4.0, required by [email protected]

  • node -v:v7.0.0
  • npm -v:3.10.8
  • yarn --version: using npm
  • watchman version:"4.7.0"

Also specify:

  1. Operating system: OSX
  2. Phone/emulator/simulator & version: ios simulator 7

Reproducible Demo

https://github.com/cliren/crna_sample

moving-to-expo-cli no idea

Most helpful comment

rm -rf .expo really solved my problem,but I need to do this everytime if I want to quit exp,and ,I found I can't use exp ba or exp bi to build standalone apps,all the same issue as @cliren

All 9 comments

Hi! Thanks for the detailed report!

I'm not able to reproduce this on a fairly similar environment, so I suspect some local state is at play. Could you please try deleting your project's .expo folder and trying this again? It's used to store some information about the packager process while it's running and seems like it may have been written to incorrectly.

Removing .expo worked after a second try (didn't work for the first time), thanks for your quick tip! Its much faster to run 'npm run ios' then running the whole thing in XDE. The error in question pops up as soon Ctrl+C, there is some background process not liking it!

rm -rf .expo really solved my problem,but I need to do this everytime if I want to quit exp,and ,I found I can't use exp ba or exp bi to build standalone apps,all the same issue as @cliren

@ickma - can you give some information about your environment? I've never seen this problem before.

  • node -v:
  • npm -v:
  • yarn --version:
  • watchman version:
  • Operating system:

@brentvatne I got the same issue when crtl-c after running the packager:

screen shot 2017-08-21 at 09 59 27

  • Node v6.8.1
  • NPM 4.1.2
  • Yarn 0.21.3
  • Watchman 4.7.0
  • OSX Sierra 10.12.3

yarn start yields the same error after this, until I run rm -rf .expo

This is from a clean React Native project following the basic tutorial from scratch.

Same issue as @davidhellsing, pressing ctrl-c will show the error. I also tried deleting my node_modules folder and reinstall everything but the error still shows up. I have to delete the .expo file every time I do development.

  • Node v7.10.1
  • NPM v4.2.0
  • OSX Sierra

I'm running into this issue on a recently created project. Error outputs look like those shared by @davidhellsing. This project is being run on two machines. The issue affects one machine, but not the other. The setups look like:

Machine 1 (shutdown errors present)

  • node v8.7.0
  • npm v5.5.1
  • yarn v1.0.2 (not directly used to setup or run the project)
  • node and npm versions are managed with nvm v0.30.2
  • macOS Sierra (10.12.6)
  • watchman v4.9.0 (was prompted by this issue https://github.com/react-community/create-react-native-app/issues/234 to install watchman via homebrew to get the app to start)

Machine 2 (no shutdown errors)

I'm wondering if any of the differentiating factors b/t these two machines (yarn presence, use of nvm, macOS version, watchman) are significant?

(edited to provide more detail about watchman install differences)

we can't repro this. if someone who has a repro case can clone the repo and experiment with fixing it that would be much appreciated

Just a hacky way, not sure if this is a fix. In tree-kill module - index.js change in the onClose method.
the module will be in /exp/node_modules/tree-kill/index.js - L.N = 91

change:

if (code != 0) {
to:
if (code == 0) {
And everything works.

Was this page helpful?
0 / 5 - 0 ratings