2016-06-21 86 views
4

在全局安裝時,似乎存在react-native的錯誤。我需要它沒有看到這個錯誤正確執行:React-native:看起來像是在全球安裝了react-native

$ react-native run-ios 
Looks like you installed react-native globally, maybe you meant react-native-cli? 
To fix the issue, run: 
npm uninstall -g react-native 
npm install -g react-native-cli 

解決方案在其他論壇貼我沒有工作,我不明白爲什麼這是行不通的。

package.json

{ 
    "name": "react-native-svgkit", 
    "version": "0.2.2", 
    "main": "Svg.js", 
    "description": "A <Svg /> element for react-native that renders Svg images using SVGKit", 
    "author": "Brent Vatne <[email protected]> (https://github.com/brentvatne)", 
    "peerDependencies": { 
    "react": "15.1.0", 
    "react-native": ">=0.4.4" 
    }, 
    "devDependencies": { 
    "react-native": ">=0.4.4", 
    "react-native-cli": "^0.1.10" 
    }, 
    "dependencies": { 
    "d3": "^3.5.5", 
    "jsdom-jscore": "^0.1.0", 
    "react-native-svg": "^2.2.0" 
    }, 
    "repository": { 
    "type": "git", 
    "url": "[email protected]:brentvatne/react-native-svgkit.git" 
    }, 
    "scripts": { 
    "start": "node /usr/local/lib/node_modules/react-native/local-cli/cli.js start" 
    } 
} 
+0

是否運行通過NPM這個命令? –

+0

是的,它位於標準的全局位置'/ usr/local/bin/react-native' –

+0

你能分享你的package.json文件嗎? –

回答

3

在我的情況下,這個問題是因爲是因爲故宮是使用自制安裝。有關此問題的說明以及如何解決該問題,請參見this gist。總之,所需的修復方法是卸載所有npm可循環安裝的軟件包,卸載節點,然後重新安裝節點,然後在不進行brew的情況下重新安裝npm。

npm list -g --depth=0 # to list all your globally installed packages 
rm -rf /usr/local/lib/node_modules 
brew uninstall node 
brew install node --without-npm 
echo prefix=~/.npm-packages >> ~/.npmrc 
curl -L https://www.npmjs.com/install.sh | sh 

,然後,你必須重新安裝了全球的裝機使用npm install -g <package_name>您所有的NPM包。

不幸的是,當我重新啓動機器時,同樣的問題又重新出現了。我目前的解決辦法是遵循建議here

npm install --save-dev react-native-cli 

任何解釋,這是怎麼回事是值得歡迎的。

+0

'npm安裝--save-dev react-native-cli'爲我解決了它。 – JHS

0

使用此在的package.json

"scripts": { 
    "android": "node node_modules/react-native/local-cli/cli.js run-android" 
} 

代替

"scripts": { 
    "android": "react-native run-android" 
}