1

I just typed npx react-native init cinetogo, and I got this error:

stw041269:mobile hugovillalobos$ npx react-native init cinetogo
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /Users/hugovillalobos/anaconda3/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
gyp ERR! stack     at Socket.stream.socket.on (internal/child_process.js:389:11)
gyp ERR! stack     at Socket.emit (events.js:198:13)
gyp ERR! stack     at Pipe._handle.close (net.js:606:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/Users/hugovillalobos/.nvm/versions/node/v10.16.0/bin/node" "/Users/hugovillalobos/.nvm/versions/node/v10.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/hugovillalobos/.npm/_npx/19812/lib/node_modules/react-native/node_modules/fsevents
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

I haven't found any reference to anybody with the same error,

HuLu ViCa
  • 5,077
  • 10
  • 43
  • 93

1 Answers1

0

According to this answer,

Node.js is built with GYP

and According to this answer,

node uses some python scripts under the hood, though Node is largely written in C++

The problem in your case is that you've installed Anaconda version 3 which has python 3.x installed. But for Node needs python 2.x to work with GYP. As you can see in the log, there is some syntax error:

gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^ 
gyp ERR! stack SyntaxError: invalid syntax

The print statement uses the syntax of Python 2.x, but your anaconda has python 3.x. So it throws Syntax Error.

Solution: Install python 2.x (2.6 or 2.7), either by installing anaconda 2 or a standalone python 2.x version, and then try to execute npx.

MRPMOHIBURRAHMAN
  • 587
  • 3
  • 14
  • 1
    I actually have python 2.7 installed in my mac but, for some reason, the default version is now 3.7. If I type `python`, I don't get 2.7 but 3.7 – HuLu ViCa Dec 17 '20 at 05:40
  • @HuLuViCa , This is because, When you are installing anaconda there supposed to be a step asking you whether to add conda/python as a default, system-wide. So after accepting that and installing Anaconda, you lose control over other standalone packages that are also included in Anaconda. Now whenever you want to access something that is already included in Anaconda, you get that version. Not the standalone one. – MRPMOHIBURRAHMAN Dec 17 '20 at 06:25
  • @HuLuViCa Solution: you need to add standalone version of python in your PATH variable by .bashrc( or other config files ) Follow this [answer](https://stackoverflow.com/a/24664480/14302873) – MRPMOHIBURRAHMAN Dec 17 '20 at 06:26