创建react-native项目时出现命令行错误

时间:2017-09-03 08:52:17

标签: react-native npm

我刚开始使用react-native项目,并且正在尝试设置一个演示项目以学习本地反应。但是,我无法通过命令行创建项目。

在安装必备库之后,我使用以下命令创建react-native项目:

react-native init AwesomeProj

我收到以下错误:

This will walk you through creating a new React Native project in /Users/ketanmalhotra/Documents/Freelance/demo-react/AwesomeProject
Installing react-native...
Consider installing yarn to make this faster: https://yarnpkg.com
npm ERR! Darwin 16.3.0
npm ERR! argv "/usr/local/Cellar/node/6.3.0/bin/node" "/usr/local/bin/npm" "install" "--save" "--save-exact" "react-native"
npm ERR! node v6.3.0
npm ERR! npm  v3.10.3
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! syscall connect

npm ERR! network connect ETIMEDOUT 151.101.36.162:443
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/ketanmalhotra/Documents/Freelance/demo-react/AwesomeProject/npm-debug.log
{ Error: Command failed: npm install --save --save-exact react-native
    at checkExecSyncError (child_process.js:475:13)
    at execSync (child_process.js:515:13)
    at run (/usr/local/lib/node_modules/react-native-cli/index.js:294:5)
    at createProject (/usr/local/lib/node_modules/react-native-cli/index.js:249:3)
    at /usr/local/lib/node_modules/react-native-cli/index.js:217:7
    at /usr/local/lib/node_modules/react-native-cli/node_modules/prompt/lib/prompt.js:316:32
    at /usr/local/lib/node_modules/react-native-cli/node_modules/async/lib/async.js:142:25
    at assembler (/usr/local/lib/node_modules/react-native-cli/node_modules/prompt/lib/prompt.js:313:9)
    at /usr/local/lib/node_modules/react-native-cli/node_modules/prompt/lib/prompt.js:322:32
    at /usr/local/lib/node_modules/react-native-cli/node_modules/prompt/lib/prompt.js:597:5
  error: null,
  cmd: 'npm install --save --save-exact react-native',
  file: '/bin/sh',
  args: 
   [ '/bin/sh',
     '-c',
     'npm install --save --save-exact react-native' ],
  options: 
   { stdio: [ [Object], [Object], [Object] ],
     shell: true,
     file: '/bin/sh',
     args: 
      [ '/bin/sh',
        '-c',
        'npm install --save --save-exact react-native' ],
     envPairs: 
      [ 'TERM_PROGRAM=Apple_Terminal',
        'SHELL=/bin/bash',
        'TERM=xterm-256color',
        'TMPDIR=/var/folders/55/sqks2tv55flg67c1bbb2d9kh0000gn/T/',
        'Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.qiouajydN4/Render',
        'TERM_PROGRAM_VERSION=388',
        'OLDPWD=/Users/ketanmalhotra',
        'TERM_SESSION_ID=473A481F-186B-4E05-B4D4-7A319C0F4D9F',
        'USER=ketanmalhotra',
        'SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.rZIxxhyFU9/Listeners',
        '__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0',
        'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin',
        'PWD=/Users/ketanmalhotra/Documents/Freelance/demo-react',
        'XPC_FLAGS=0x0',
        'XPC_SERVICE_NAME=0',
        'SHLVL=1',
        'HOME=/Users/ketanmalhotra',
        'LOGNAME=ketanmalhotra',
        'LC_CTYPE=UTF-8',
        'DISPLAY=/private/tmp/com.apple.launchd.3GdGOWMzei/org.macosforge.xquartz:0',
        '_=/usr/local/bin/react-native' ] },
  envPairs: 
   [ 'TERM_PROGRAM=Apple_Terminal',
     'SHELL=/bin/bash',
     'TERM=xterm-256color',
     'TMPDIR=/var/folders/55/sqks2tv55flg67c1bbb2d9kh0000gn/T/',
     'Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.qiouajydN4/Render',
     'TERM_PROGRAM_VERSION=388',
     'OLDPWD=/Users/ketanmalhotra',
     'TERM_SESSION_ID=473A481F-186B-4E05-B4D4-7A319C0F4D9F',
     'USER=ketanmalhotra',
     'SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.rZIxxhyFU9/Listeners',
     '__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0',
     'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin',
     'PWD=/Users/ketanmalhotra/Documents/Freelance/demo-react',
     'XPC_FLAGS=0x0',
     'XPC_SERVICE_NAME=0',
     'SHLVL=1',
     'HOME=/Users/ketanmalhotra',
     'LOGNAME=ketanmalhotra',
     'LC_CTYPE=UTF-8',
     'DISPLAY=/private/tmp/com.apple.launchd.3GdGOWMzei/org.macosforge.xquartz:0',
     '_=/usr/local/bin/react-native' ],
  stderr: null,
  stdout: null,
  pid: 79752,
  output: [ null, null, null ],
  signal: null,
  status: 1 }
Command `npm install --save --save-exact react-native` failed.

我试图找到这个问题的解决方案,但找不到任何有效的方法。任何人都知道如何解决这个问题?

P.S。我在Mac上做这个(如果这有什么不同)

4 个答案:

答案 0 :(得分:4)

我检查了互联网问题,还ping了registry.npmjs.org,一切正常。为了解决这个问题,我使用以下命令安装了纱线:

brew install yarn

似乎解决了这个问题。如果任何人在使用react-native开始时遇到同样的问题,我会把它放在这里。

答案 1 :(得分:1)

npm cache clean --force

运行此命令首先为我解决了该问题。

答案 2 :(得分:0)

npm cache clean --force 
brew install yarn
npm install --save --save-exact react-native

或手动安装纱线。

cd /opt
wget https://yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz

然后运行

npm install --save --save-exact react-native

答案 3 :(得分:0)

我解决了这个问题,手动下载并安装了纱线

使用命令:

yarn config set "strict-ssl" false -g  
yarn add react-native --exact